您好,请问怎样才能在private中定义控件和控件的方法? 我下面的代码没有通过;将
TForm1 = class(TForm) 放在private 外也不行,应该怎么做? 谢谢您。unit Umain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
private
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject); { Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:='12';
end;end.
TForm1 = class(TForm) 放在private 外也不行,应该怎么做? 谢谢您。unit Umain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
private
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject); { Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption:='12';
end;end.
你看看看吧.
在dfm文件中有他们的描述,如果你只是申明这样的变量,在dfm中找不到对应的描述信息,自然是不行的
begin
Label1 := TLabel.Create(Self);
Button1 := TButton.Create(Self); Label1.Parent := Self;
Button1.Parent := Self;
Button1.Top := 25;
Button1.OnClick := Button1Click;
end;