Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
Posted by Daniel - 904 Views
This article will give you an example of runtime-form-creation, or how to create child forms in a Delphi MDI application using the component array. It means that the forms will be created on runtime. You can create and remove forms not in the design mode but when the program is running.
The program consists of an MDIForm, there is a Main Menu on the form and the screenshot is below:
Under the [File] menu there is a menu item [New Window]. If you click on that item, a new child form will be created and the reference to it will be added under the [Windows] menu. If you close the just created form, the instance of the form will be removed and its reference under the [Windows] menu will be deleted.
You can also change the TileMode of the created child forms by choosing on of the available modes: [Tile Horizontally] or [Tile Vertically] from the [Layout] menu. The form creation is done at runtime by the procedure below:
var Daftar : TMenuItem;
i : integer;
boolCaptionExist : boolean;
begin
SetLength(arrForm,Length(arrForm)+1);
arrForm[Length(arrForm)-1] := TForm.Create(Form1);
arrForm[Length(arrForm)-1].FormStyle := fsMDIChild;
arrForm[Length(arrForm)-1].OnClose := FormChildClose;
boolCaptionExist := false;
for i := Low(arrForm) to High(arrForm) do
begin
if arrForm[i].Caption = ‘Window ‘ + IntToStr(Length(arrForm)) then
begin
boolCaptionExist := True;
end;
end;
if boolCaptionExist then
arrForm[Length(arrForm)-1].Caption := ‘Window ‘ + IntToStr(Length(arrForm)+1)
else
arrForm[Length(arrForm)-1].Caption := ‘Window ‘ + IntToStr(Length(arrForm));
arrForm[Length(arrForm)-1].Show;
Daftar := TMenuItem.Create(mmWindows);
Daftar.Caption := ‘Window ‘ + IntToStr(Length(arrForm));
Daftar.OnClick := WindowListClick;
mmWindows.Insert(mmWindows.Count,Daftar);
end;
There is an array altering process performed by the SetLength command. arrForm() is a dynamic array where the child form instances stored. The datatype of the array is TForm because we want to store forms in the array, and the declaration which you can also find it at the top of the full code is below:
Everytime a child form is created, the length of the array will be added by 1 and vice versa. The full example project code is included in this artcle, just download it if you want to learn more about runtime-form-creation.
Download the example project (9 KB)
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- CPort Component (Serial port interface component for Delphi)
- MPEG Audio Component (A Delphi component to play audio files)
- FlatStyle Delphi controls (Flat controls for your Delphi application)
- Delphi SMSCodec (SMS Processing Component)
- An example: Using CPort Delphi Component to read data from your cellphone
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!

















