Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

ID: 13443, Dynamic form creation without changing the rest of your code.

by Thomas Quester Email:

Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 4.0 2496 downloads
Copyright: No significant restrictions

Size: 2,343 bytes
Updated on Thu, 17 Jun 1999 00:00:00 GMT
Originally uploaded on Thu, 17 Jun 1999 00:00:00 GMT
SHA1 Hash: 8C20A90C584ACF533B6098085434F193BA016081
MD5 Hash: 4E5CF36BB7BD5AF7367D6B5C07F27DC6

    Explore the files in this upload

A drawback in Delphi is, that every form is created at startup. This may take a long time and also costs a lot of time.

A better way is to create a form in the instance it is needed using Application.FormCreate. But before you go through your
project and add a lot of Application.FormCreates´s on every position, you need a form, go on reading. This example creates
the form in the instance it. The rest of the project needs not to be changed.

You can write Form2.Edit1.Text := 'hallo', even if Form2 is not created yet.

The trick is to replace the global Variable Form2 with a function Form2. It has been a common practice in our company
to rename to form to FForm2.

The function to create the form is

function Form2 : TFForm2;
if FForm2 = NIL then Application.CreateForm(FForm2,TFForm2);
result := FForm2;

Now, the rest of the project still "thinks" is is dealing with the variable called Form2, but instead, it is dealing with a function that has the same name. The function looks if the form is created and if not does so.

This is one of the common Arabella patterns. If Arabella is installed, Arabella can automatically modify your source code with the command: Arabella/Templates. Then select "Dynamic form creator" and choose the form from the combo box.
Arabella´s site:

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03