Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Variety of form create

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.

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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:
    [code]
    form1 := TForm1.create(form1);
    [/code]
    doesn't give Form1 a parent component, and should be
    [code]
    form1 := TForm1.create(Application);
    [/code]
    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:
    [code]
    unit Unit1;

    interface

    uses
    Unit2;

    implementation

    end.
    [/code]
    Unit2 is first fully compiled and check before Unit1.
    [code]
    unit Unit1;

    interface

    implementation

    uses
    Unit2;

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

    interface

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

    implementation

    uses
    Unit1; // Works with either version of Unit1

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

    interface

    uses
    Forms;

    type
    TForm1 = class(TForm);
    end;

    implementation

    end.
    [/code]
    [code]
    unit Unit4;

    interface

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

    implementation

    uses
    Forms;

    end.
    [/code]

  • Chaitanya_PuneChaitanya_Pune Posts: 87Member
    : : 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:
    : [code]
    : form1 := TForm1.create(form1);
    : [/code]
    : doesn't give Form1 a parent component, and should be
    : [code]
    : form1 := TForm1.create(Application);
    : [/code]
    : 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:
    : [code]
    : unit Unit1;
    :
    : interface
    :
    : uses
    : Unit2;
    :
    : implementation
    :
    : end.
    : [/code]
    : Unit2 is first fully compiled and check before Unit1.
    : [code]
    : unit Unit1;
    :
    : interface
    :
    : implementation
    :
    : uses
    : Unit2;
    :
    : end.
    : [/code]
    : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
    : [code]
    : unit Unit2;
    :
    : interface
    :
    : uses
    : Unit1; // Gives error if "uses Unit2;" is in interface section.
    :
    : implementation
    :
    : uses
    : Unit1; // Works with either version of Unit1
    :
    : end.
    : [/code]
    : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
    : [code]
    : unit Unit3;
    :
    : interface
    :
    : uses
    : Forms;
    :
    : type
    : TForm1 = class(TForm);
    : end;
    :
    : implementation
    :
    : end.
    : [/code]
    : [code]
    : unit Unit4;
    :
    : interface
    :
    : type
    : TForm1 = class(TForm); // Unknown identifier error: TForm
    : end;
    :
    : implementation
    :
    : uses
    : Forms;
    :
    : end.
    : [/code]
    : ----------------------------------------------------------------------

    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?
    :

  • zibadianzibadian Posts: 6,349Member
    : : : 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:
    : : [code]
    : : form1 := TForm1.create(form1);
    : : [/code]
    : : doesn't give Form1 a parent component, and should be
    : : [code]
    : : form1 := TForm1.create(Application);
    : : [/code]
    : : 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:
    : : [code]
    : : unit Unit1;
    : :
    : : interface
    : :
    : : uses
    : : Unit2;
    : :
    : : implementation
    : :
    : : end.
    : : [/code]
    : : Unit2 is first fully compiled and check before Unit1.
    : : [code]
    : : unit Unit1;
    : :
    : : interface
    : :
    : : implementation
    : :
    : : uses
    : : Unit2;
    : :
    : : end.
    : : [/code]
    : : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
    : : [code]
    : : unit Unit2;
    : :
    : : interface
    : :
    : : uses
    : : Unit1; // Gives error if "uses Unit2;" is in interface section.
    : :
    : : implementation
    : :
    : : uses
    : : Unit1; // Works with either version of Unit1
    : :
    : : end.
    : : [/code]
    : : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
    : : [code]
    : : unit Unit3;
    : :
    : : interface
    : :
    : : uses
    : : Forms;
    : :
    : : type
    : : TForm1 = class(TForm);
    : : end;
    : :
    : : implementation
    : :
    : : end.
    : : [/code]
    : : [code]
    : : unit Unit4;
    : :
    : : interface
    : :
    : : type
    : : TForm1 = class(TForm); // Unknown identifier error: TForm
    : : end;
    : :
    : : implementation
    : :
    : : uses
    : : Forms;
    : :
    : : end.
    : : [/code]
    : : ----------------------------------------------------------------------
    :
    : 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.
  • Chaitanya_PuneChaitanya_Pune Posts: 87Member
    : : : : 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:
    : : : [code]
    : : : form1 := TForm1.create(form1);
    : : : [/code]
    : : : doesn't give Form1 a parent component, and should be
    : : : [code]
    : : : form1 := TForm1.create(Application);
    : : : [/code]
    : : : 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:
    : : : [code]
    : : : unit Unit1;
    : : :
    : : : interface
    : : :
    : : : uses
    : : : Unit2;
    : : :
    : : : implementation
    : : :
    : : : end.
    : : : [/code]
    : : : Unit2 is first fully compiled and check before Unit1.
    : : : [code]
    : : : unit Unit1;
    : : :
    : : : interface
    : : :
    : : : implementation
    : : :
    : : : uses
    : : : Unit2;
    : : :
    : : : end.
    : : : [/code]
    : : : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
    : : : [code]
    : : : unit Unit2;
    : : :
    : : : interface
    : : :
    : : : uses
    : : : Unit1; // Gives error if "uses Unit2;" is in interface section.
    : : :
    : : : implementation
    : : :
    : : : uses
    : : : Unit1; // Works with either version of Unit1
    : : :
    : : : end.
    : : : [/code]
    : : : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
    : : : [code]
    : : : unit Unit3;
    : : :
    : : : interface
    : : :
    : : : uses
    : : : Forms;
    : : :
    : : : type
    : : : TForm1 = class(TForm);
    : : : end;
    : : :
    : : : implementation
    : : :
    : : : end.
    : : : [/code]
    : : : [code]
    : : : unit Unit4;
    : : :
    : : : interface
    : : :
    : : : type
    : : : TForm1 = class(TForm); // Unknown identifier error: TForm
    : : : end;
    : : :
    : : : implementation
    : : :
    : : : uses
    : : : Forms;
    : : :
    : : : end.
    : : : [/code]
    : : : ----------------------------------------------------------------------
    : :
    : : 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?


  • zibadianzibadian Posts: 6,349Member
    : : : : : 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:
    : : : : [code]
    : : : : form1 := TForm1.create(form1);
    : : : : [/code]
    : : : : doesn't give Form1 a parent component, and should be
    : : : : [code]
    : : : : form1 := TForm1.create(Application);
    : : : : [/code]
    : : : : 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:
    : : : : [code]
    : : : : unit Unit1;
    : : : :
    : : : : interface
    : : : :
    : : : : uses
    : : : : Unit2;
    : : : :
    : : : : implementation
    : : : :
    : : : : end.
    : : : : [/code]
    : : : : Unit2 is first fully compiled and check before Unit1.
    : : : : [code]
    : : : : unit Unit1;
    : : : :
    : : : : interface
    : : : :
    : : : : implementation
    : : : :
    : : : : uses
    : : : : Unit2;
    : : : :
    : : : : end.
    : : : : [/code]
    : : : : The interface part of Unit1 may be compiled before Unit2 is compiled. The difference becomes more clear if you create a circular reference:
    : : : : [code]
    : : : : unit Unit2;
    : : : :
    : : : : interface
    : : : :
    : : : : uses
    : : : : Unit1; // Gives error if "uses Unit2;" is in interface section.
    : : : :
    : : : : implementation
    : : : :
    : : : : uses
    : : : : Unit1; // Works with either version of Unit1
    : : : :
    : : : : end.
    : : : : [/code]
    : : : : Also uses in the interface part gives access to it's types/routines in the interface part of the referencing unit. Example:
    : : : : [code]
    : : : : unit Unit3;
    : : : :
    : : : : interface
    : : : :
    : : : : uses
    : : : : Forms;
    : : : :
    : : : : type
    : : : : TForm1 = class(TForm);
    : : : : end;
    : : : :
    : : : : implementation
    : : : :
    : : : : end.
    : : : : [/code]
    : : : : [code]
    : : : : unit Unit4;
    : : : :
    : : : : interface
    : : : :
    : : : : type
    : : : : TForm1 = class(TForm); // Unknown identifier error: TForm
    : : : : end;
    : : : :
    : : : : implementation
    : : : :
    : : : : uses
    : : : : Forms;
    : : : :
    : : : : end.
    : : : : [/code]
    : : : : ----------------------------------------------------------------------
    : : :
    : : : 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?
    :
    :
    :
    [size=4][b]CreateForm() sets the mainform property, if it is not set.[/b][/size] 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 [b]not[/b] 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.
Sign In or Register to comment.