Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Variety of form create Posted by Chaitanya_Pune on 29 Sept 2006 at 3:37 AM
I am using Delphi5.0. What is the difference between

form1 := TForm1.create(form1);

and

Application.CreateForm(Tform1, form1);


In which context I should use each?

Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
Report
Re: Variety of form create Posted by zibadian on 29 Sept 2006 at 3:50 AM
: I am using Delphi5.0. What is the difference between
:
: form1 := TForm1.create(form1);
:
: and
:
: Application.CreateForm(Tform1, form1);
:
:
: In which context I should use each?
:
: Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
:
First of all the first:
  form1 := TForm1.create(form1);

doesn't give Form1 a parent component, and should be
  form1 := TForm1.create(Application);

The main difference between TForm1.Create() and CreateForm() is that CreateForm() checks the MainForm of the application and sets it if it doesn't exist. Otherwise both methods are interchangable.

The location of the uses list determines the order in which it is compiled. Example:
unit Unit1;

interface

uses
  Unit2;

implementation

end.

Unit2 is first fully compiled and check before Unit1.
unit Unit1;

interface

implementation

uses
  Unit2;

end.

The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
unit Unit2;

interface

uses
  Unit1; // Gives error if "uses Unit2;" is in interface section.

implementation

uses
  Unit1; // Works with either version of Unit1

end.

Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
unit Unit3;

interface

uses
  Forms; 

type
  TForm1 = class(TForm);
  end;

implementation

end.

unit Unit4;

interface

type
  TForm1 = class(TForm); // Unknown identifier error: TForm
  end;

implementation

uses
  Forms; 

end.


Report
Re: Variety of form create Posted by Chaitanya_Pune on 4 Oct 2006 at 4:38 AM
: : I am using Delphi5.0. What is the difference between
: :
: : form1 := TForm1.create(form1);
: :
: : and
: :
: : Application.CreateForm(Tform1, form1);
: :
: :
: : In which context I should use each?
: :
: : Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
: :
: First of all the first:
:
:   form1 := TForm1.create(form1);
: 

: doesn't give Form1 a parent component, and should be
:
:   form1 := TForm1.create(Application);
: 

: The main difference between TForm1.Create() and CreateForm() is that CreateForm() checks the MainForm of the application and sets it if it doesn't exist. Otherwise both methods are interchangable.
:
: The location of the uses list determines the order in which it is compiled. Example:
:
: unit Unit1;
: 
: interface
: 
: uses
:   Unit2;
: 
: implementation
: 
: end.
: 

: Unit2 is first fully compiled and check before Unit1.
:
: unit Unit1;
: 
: interface
: 
: implementation
: 
: uses
:   Unit2;
: 
: end.
: 

: The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
:
: unit Unit2;
: 
: interface
: 
: uses
:   Unit1; // Gives error if "uses Unit2;" is in interface section.
: 
: implementation
: 
: uses
:   Unit1; // Works with either version of Unit1
: 
: end.
: 

: Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
:
: unit Unit3;
: 
: interface
: 
: uses
:   Forms; 
: 
: type
:   TForm1 = class(TForm);
:   end;
: 
: implementation
: 
: end.
: 

:
: unit Unit4;
: 
: interface
: 
: type
:   TForm1 = class(TForm); // Unknown identifier error: TForm
:   end;
: 
: implementation
: 
: uses
:   Forms; 
: 
: end.
: 

: ----------------------------------------------------------------------

Hi, Zibadian Thanks for help. But still I don't understand the difference between From.create and Application.createform. Can u make it more clear?
You have said something about main form? What is it?
:

Report
Re: Variety of form create Posted by zibadian on 4 Oct 2006 at 3:36 PM
: : : I am using Delphi5.0. What is the difference between
: : :
: : : form1 := TForm1.create(form1);
: : :
: : : and
: : :
: : : Application.CreateForm(Tform1, form1);
: : :
: : :
: : : In which context I should use each?
: : :
: : : Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
: : :
: : First of all the first:
: :
: :   form1 := TForm1.create(form1);
: : 

: : doesn't give Form1 a parent component, and should be
: :
: :   form1 := TForm1.create(Application);
: : 

: : The main difference between TForm1.Create() and CreateForm() is that CreateForm() checks the MainForm of the application and sets it if it doesn't exist. Otherwise both methods are interchangable.
: :
: : The location of the uses list determines the order in which it is compiled. Example:
: :
: : unit Unit1;
: : 
: : interface
: : 
: : uses
: :   Unit2;
: : 
: : implementation
: : 
: : end.
: : 

: : Unit2 is first fully compiled and check before Unit1.
: :
: : unit Unit1;
: : 
: : interface
: : 
: : implementation
: : 
: : uses
: :   Unit2;
: : 
: : end.
: : 

: : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
: :
: : unit Unit2;
: : 
: : interface
: : 
: : uses
: :   Unit1; // Gives error if "uses Unit2;" is in interface section.
: : 
: : implementation
: : 
: : uses
: :   Unit1; // Works with either version of Unit1
: : 
: : end.
: : 

: : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
: :
: : unit Unit3;
: : 
: : interface
: : 
: : uses
: :   Forms; 
: : 
: : type
: :   TForm1 = class(TForm);
: :   end;
: : 
: : implementation
: : 
: : end.
: : 

: :
: : unit Unit4;
: : 
: : interface
: : 
: : type
: :   TForm1 = class(TForm); // Unknown identifier error: TForm
: :   end;
: : 
: : implementation
: : 
: : uses
: :   Forms; 
: : 
: : end.
: : 

: : ----------------------------------------------------------------------
:
: Hi, Zibadian Thanks for help. But still I don't understand the difference between From.create and Application.createform. Can u make it more clear?
: You have said something about main form? What is it?
: :
:
:
The main form is the first form created by the application. When that form is closed, the application closes. It is stored in the TApplication.MainForm property (see help files), hence the name main form. The call Form.Create() only creates a new form object, but does not check if it should is the first form created (= mainform). Since the mainform is also the container for the main windows handle (necessary for certain API calls), that handle is also not created when you use Form.Create().
The call TApplication.CreateForm() calls Form.Create() to create the object. Then it checks if the MainForm property is set, and if necessary sets it with the newly created form. It also checks if that form as a valid handle. If it hasn't got one, that handle is also created.
If that main handle is missing, all dialogs, and other forms will appear in the taskbar as separate tasks.
Report
Re: Variety of form create Posted by Chaitanya_Pune on 5 Oct 2006 at 3:47 AM
: : : : I am using Delphi5.0. What is the difference between
: : : :
: : : : form1 := TForm1.create(form1);
: : : :
: : : : and
: : : :
: : : : Application.CreateForm(Tform1, form1);
: : : :
: : : :
: : : : In which context I should use each?
: : : :
: : : : Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
: : : :
: : : First of all the first:
: : :
: : :   form1 := TForm1.create(form1);
: : : 

: : : doesn't give Form1 a parent component, and should be
: : :
: : :   form1 := TForm1.create(Application);
: : : 

: : : The main difference between TForm1.Create() and CreateForm() is that CreateForm() checks the MainForm of the application and sets it if it doesn't exist. Otherwise both methods are interchangable.
: : :
: : : The location of the uses list determines the order in which it is compiled. Example:
: : :
: : : unit Unit1;
: : : 
: : : interface
: : : 
: : : uses
: : :   Unit2;
: : : 
: : : implementation
: : : 
: : : end.
: : : 

: : : Unit2 is first fully compiled and check before Unit1.
: : :
: : : unit Unit1;
: : : 
: : : interface
: : : 
: : : implementation
: : : 
: : : uses
: : :   Unit2;
: : : 
: : : end.
: : : 

: : : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
: : :
: : : unit Unit2;
: : : 
: : : interface
: : : 
: : : uses
: : :   Unit1; // Gives error if "uses Unit2;" is in interface section.
: : : 
: : : implementation
: : : 
: : : uses
: : :   Unit1; // Works with either version of Unit1
: : : 
: : : end.
: : : 

: : : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
: : :
: : : unit Unit3;
: : : 
: : : interface
: : : 
: : : uses
: : :   Forms; 
: : : 
: : : type
: : :   TForm1 = class(TForm);
: : :   end;
: : : 
: : : implementation
: : : 
: : : end.
: : : 

: : :
: : : unit Unit4;
: : : 
: : : interface
: : : 
: : : type
: : :   TForm1 = class(TForm); // Unknown identifier error: TForm
: : :   end;
: : : 
: : : implementation
: : : 
: : : uses
: : :   Forms; 
: : : 
: : : end.
: : : 

: : : ----------------------------------------------------------------------
: :
: : Hi, Zibadian Thanks for help. But still I don't understand the difference between From.create and Application.createform. Can u make it more clear?
: : You have said something about main form? What is it?
: : :
: :
: :
: The main form is the first form created by the application. When that form is closed, the application closes. It is stored in the TApplication.MainForm property (see help files), hence the name main form. The call Form.Create() only creates a new form object, but does not check if it should is the first form created (= mainform). Since the mainform is also the container for the main windows handle (necessary for certain API calls), that handle is also not created when you use Form.Create().
: The call TApplication.CreateForm() calls Form.Create() to create the object. Then it checks if the MainForm property is set, and if necessary sets it with the newly created form. It also checks if that form as a valid handle. If it hasn't got one, that handle is also created.
: If that main handle is missing, all dialogs, and other forms will appear in the taskbar as separate tasks.
:
------------------------------------------------------------------------

Thanks.
In my DPR I have written following two staments

Application.CreateForm(TFrmInstall, FrmInstall);
Application.CreateForm(TfrmAbout, frmAbout);

Also I have not set mainform property of the TApplication.

So what will be the consequences of the same?

Which form will be set as TApplication.mainform property and Why?

How it affects further execution?


Report
Re: Variety of form create Posted by zibadian on 5 Oct 2006 at 6:48 AM
: : : : : I am using Delphi5.0. What is the difference between
: : : : :
: : : : : form1 := TForm1.create(form1);
: : : : :
: : : : : and
: : : : :
: : : : : Application.CreateForm(Tform1, form1);
: : : : :
: : : : :
: : : : : In which context I should use each?
: : : : :
: : : : : Also I would like to know the difference between the uses clause of Interface section and the same of the Implementation section.
: : : : :
: : : : First of all the first:
: : : :
: : : :   form1 := TForm1.create(form1);
: : : : 

: : : : doesn't give Form1 a parent component, and should be
: : : :
: : : :   form1 := TForm1.create(Application);
: : : : 

: : : : The main difference between TForm1.Create() and CreateForm() is that CreateForm() checks the MainForm of the application and sets it if it doesn't exist. Otherwise both methods are interchangable.
: : : :
: : : : The location of the uses list determines the order in which it is compiled. Example:
: : : :
: : : : unit Unit1;
: : : : 
: : : : interface
: : : : 
: : : : uses
: : : :   Unit2;
: : : : 
: : : : implementation
: : : : 
: : : : end.
: : : : 

: : : : Unit2 is first fully compiled and check before Unit1.
: : : :
: : : : unit Unit1;
: : : : 
: : : : interface
: : : : 
: : : : implementation
: : : : 
: : : : uses
: : : :   Unit2;
: : : : 
: : : : end.
: : : : 

: : : : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
: : : :
: : : : unit Unit2;
: : : : 
: : : : interface
: : : : 
: : : : uses
: : : :   Unit1; // Gives error if "uses Unit2;" is in interface section.
: : : : 
: : : : implementation
: : : : 
: : : : uses
: : : :   Unit1; // Works with either version of Unit1
: : : : 
: : : : end.
: : : : 

: : : : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
: : : :
: : : : unit Unit3;
: : : : 
: : : : interface
: : : : 
: : : : uses
: : : :   Forms; 
: : : : 
: : : : type
: : : :   TForm1 = class(TForm);
: : : :   end;
: : : : 
: : : : implementation
: : : : 
: : : : end.
: : : : 

: : : :
: : : : unit Unit4;
: : : : 
: : : : interface
: : : : 
: : : : type
: : : :   TForm1 = class(TForm); // Unknown identifier error: TForm
: : : :   end;
: : : : 
: : : : implementation
: : : : 
: : : : uses
: : : :   Forms; 
: : : : 
: : : : end.
: : : : 

: : : : ----------------------------------------------------------------------
: : :
: : : Hi, Zibadian Thanks for help. But still I don't understand the difference between From.create and Application.createform. Can u make it more clear?
: : : You have said something about main form? What is it?
: : : :
: : :
: : :
: : The main form is the first form created by the application. When that form is closed, the application closes. It is stored in the TApplication.MainForm property (see help files), hence the name main form. The call Form.Create() only creates a new form object, but does not check if it should is the first form created (= mainform). Since the mainform is also the container for the main windows handle (necessary for certain API calls), that handle is also not created when you use Form.Create().
: : The call TApplication.CreateForm() calls Form.Create() to create the object. Then it checks if the MainForm property is set, and if necessary sets it with the newly created form. It also checks if that form as a valid handle. If it hasn't got one, that handle is also created.
: : If that main handle is missing, all dialogs, and other forms will appear in the taskbar as separate tasks.
: :
: ------------------------------------------------------------------------
:
: Thanks.
: In my DPR I have written following two staments
:
: Application.CreateForm(TFrmInstall, FrmInstall);
: Application.CreateForm(TfrmAbout, frmAbout);
:
: Also I have not set mainform property of the TApplication.
:
: So what will be the consequences of the same?
:
: Which form will be set as TApplication.mainform property and Why?
:
: How it affects further execution?
:
:
:
CreateForm() sets the mainform property, if it is not set. Which means that before the first call to CreateForm() the mainform is nil (=not set), thus FrmInstall is set as the mainform. During the second call to CreateFrom() the mainform is set to FrmInstall, thus FrmAbout is not set as the mainform.
As for the further execution: FrmInstall holds the main API handle; its title is shown in the taskbar; if you press the x to close it, the program completely closes; FrmInstall will be the first form the user sees by default; that form will hold the mainmenu.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.