Показать сообщение отдельно
  #4  
Старый 01.06.2011, 15:18
Аватар для NumLock
NumLock NumLock вне форума
Let Me Show You
 
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
По умолчанию

простейший пример перегрузки конструктора и использования классового метода:

Код:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
  private
    { Private declarations }
    ACaption: String;
    x, y, z: Integer;
  public
    { Public declarations }
    class function CreateForm(ACaption: String; x, y, z: Integer): TForm2; overload;
    constructor CreateForm(AOwner: TComponent; ACaption: String; x, y, z: Integer); overload;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

{ TForm2 }

constructor TForm2.CreateForm(AOwner: TComponent; ACaption: String; x, y, z: Integer);
begin
  inherited Create(AOwner);
  Self.ACaption:=ACaption;
  Self.x:=x;
  Self.y:=y;
  Self.z:=z;
  Label1.Caption:=ACaption;
end;

class function TForm2.CreateForm(ACaption: String; x, y, z: Integer): TForm2;
begin
  Result:=TForm2.CreateForm(Application, ACaption, x, y, z);
  Result.ShowModal;
  Result.Free;
end;

end.

использование:

Код:
unit Unit1;

interface

uses
  Unit2,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  TForm2.CreateForm('Button1Click', 1, 2, 4);
end;

end.
__________________
Пишу программы за еду.
__________________
Ответить с цитированием