如果这个问题看起来很愚蠢,我很抱歉,但是在过去的几个小时里我似乎无法正常使用我的头脑。
我有记录,
type
TMain = record
Sub:Array of TSubMain; //another record
Button:TsSpeedButton; //this is what we need!
end;
变量
Main:Array of TMain;
及功能:
procedure TFrameSkilLView.CreateButtons(MainBtns,SubMainBtns:byte;title:Array of string);
var i,t,l,w,h:word;
section:string;
begin
l := 41; t:= 57; w := 58; h := 25;
section := 'TOOLBTN_SKILLS_MAIN';
for i := 0 to MainBtns + subMainBtns - 1 do
with TsSpeedButton.Create(nil) do begin
Width := w; Height := h; Top := t; Left := l;
if(i = 0) then SkinData.SkinSection := section + '_C' else skindata.SkinSection := section;
caption := title[i];
Parent := Self;
inc(l,w+4);
if(i = MainBtns - 1) then begin
l := 52; t := 83; w := 64; h := 28;
section := 'TOOLBTN_SKILLS_SUBMAIN';
end;
end;
end;
让我们重点关注循环“for i := 0 to MainBtns + subMainBtns - 1”。我想将下面创建的按钮添加到上面创建的名为“Main:Array of Tmain”的数组中。
它应该看起来像这样:
for i:=0 to X do
with TsSpeedButton.Create(nil) do begin
Main[i] := this; //where this is the created sSpeedButton.
然而,这段代码甚至无法编译,所以我要求一种可行的方法来完成我想要做的事情。
谢谢。
最佳答案
首先,“这个”是 C++,而不是 Pascal。 Delphi 版本是“Self”。其次,您不能通过名称引用 with-ed 对象。你最好根本不使用 with
。尝试这样的事情:
for i:=0 to X do
begin
tempButton := TsSpeedButton.Create(nil);
Main[i] := tempButton;
//whatever else
end;
关于delphi - 如何将运行时创建的按钮添加到数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1228671/