Главная страница | назад





Article #17887: Creating new constructors

 Question and Answer Database

FAQ2887D.txt   Creating new constructors
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
Is it possible to create a form that accepts additional parameters
for the create method?


Answer:
Simply replace the Create constructor to your form class to accept
additional parameters.

Example:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    constructor CreateWithCaption(aOwner: TComponent;
                                  aCaption: string);
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

constructor TForm2.CreateWithCaption(aOwner: TComponent;
                                     aCaption: string);
begin
  Create(aOwner);
  Caption := aCaption;
end;

uses Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Unit2.Form2 :=
    Unit2.TForm2.CreateWithCaption(Application, 'My Caption');
  Unit2.Form2.Show;
end;


7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99