AS:与主题启动通信中接听长得太。总的结果是一样http://pastebin.ca/2426760
procedure TForm1.CreateButton(VAR Button: TButton; CONST L: Integer; CONST T: Integer);
也就是说Pascal语言的基础知识,如何将参数传递给过程/函数。
http://docwiki.embarcadero.com/RADStudio/XE4/en/Parameters_(Delphi)
其实,我不认为这是与参数
按钮=零,这意味着“Button1的”和“将Button2”的值的任何问题都不会发送,但是
http://pastebin.ca/2427238
Kudoes比尔为察觉THI秒。使用单独的属性来定位控件既效率低下,又容易出现复制粘贴错误。
使用第二个链接:
procedure TForm1.CreateButton(out Button: TButton; const L: Integer; const T: Integer);
begin
Button:= TButton.Create(Self);
Button.Parent:= Self;
Button.SetBounds(L, T, 100, 50);
end;
其实你是做什么用的指针到新创建的按钮? 在你的代码中,你只需要松开它们!
procedure TForm1.FormCreate(Sender: TObject);
Var
Button1, Button2: TButton;
begin
...
end;
在这个代码中,这些指针会丢失!如果你确实需要这些值 - 在程序之外传递它们。如果你不 - 不问他们 - http://en.wikipedia.org/wiki/YAGNIhttp://en.wikipedia.org/wiki/KISS_principle
Procedure TForm1.CreateButton(const L, T: Integer);
begin
With TButton.Create(Self) do begin
Parent := Self;
SetBounds(L, T, 100, 50);
Caption := 'Caption at ' + IntToStr(T);
Name := 'Name at ' + IntToStr(L);
End;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
B1.CreateButton(100, 50); //Sending properties
B2.CreateButton(200, 40); //Sending properties
end;
我们的B1,B2 ......
你声称要在表格上的2个按钮,但你的代码显示您尝试在第二张表格上制作三条表格和一个按钮,并在第三张表格上单击一个按钮。那么你真的想要什么?你是否检查过B1和B2表单是否是在尝试添加按钮时创建的?
也许你真的想
procedure TForm1.FormCreate(Sender: TObject);
begin
SELF.CreateButton(100, 50); //Sending properties
SELF.CreateButton(200, 40); //Sending properties
end;
然后一起去DRY原则,并保持所有的变量在一个地方。
http://docwiki.embarcadero.com/Libraries/XE2/en/System.Types.TPoint
Procedure TForm1.CreateButtons(const a: array of TPoint);
Var p: TPoint;
Begin
for p in a do
CreateButton(p.x, p.y);
End;
type TPointDynArray = array of TPoint;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateButtons(TPointDynArray.Create(
Point(100,50), Point(200, 40)));
end;
荣誉给Delphi array initialization
之后,您可以随时添加更多的坐标数组,并保持一致。 好,打倒这个德尔福7个异能会 - 有些冗余 - 编码像
const BtnCnt = 2;
BtnLocations : array [1..BtnCnt] of TSize = (
(cx: 100, cy: 50), (cx: 200, cy: 40)
);
Procedure TForm1.CreateButtons(const a: array of TSize);
Var i: integer;
Begin
for i := Low(a) to High(a) do
with a[i] do
CreateButton(cx, cy);
End;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateButtons(BtnLocations);
end;
不过,虽然德尔福5和Delphi的7是伟大的版本,他们是非常不合时宜的。我绝对建议你要么upgradeing德尔福XE或更近,或侧迈向CodeTyphon
TForm1 = class(TForm) //Declaring the procedure
procedure CreateButton(Button: TButton; L: Integer; T: Integer);
声明,在窗体类的出版部分中的一个通用的过程也不是一个很好的风格。你最好在PRIVATE部分声明它们。坚持“最低可见度”将有助于使相互依赖性得到控制。否则一年之内你的计划就会变成意大利面条混乱,你不能在不破坏其他一切的情况下改变任何东西。我现在正在做一个拥有10多年历史的项目,我看到“一切都是公开的”后果非常明显。这是一个很大的痛苦!
你是什么意思“不工作”?什么时候 ?哪些错误?没有人可以跳进你的头,用你的眼睛看。请阅读http://www.catb.org/~esr/faqs/smart-questions.html –
在CreateButton中有两个Button.Height ...将第二个更改为Button.Top:= T; – Bill
我是sry,我的意思是没有创建按钮1,2 –