Delphi 如何将运行时创建的按钮添加到数组中?

Delphi 如何将运行时创建的按钮添加到数组中?,delphi,Delphi,如果这个问题看起来很愚蠢,我很抱歉,但在过去的几个小时里我似乎不能正确地运用我的头脑 我有记录 type TMain = record Sub:Array of TSubMain; //another record Button:TsSpeedButton; //this is what we need! end; 变数 Main:Array of TMain; 和功能: procedure TFrameSkilLView.CreateButtons(MainBtn

如果这个问题看起来很愚蠢,我很抱歉,但在过去的几个小时里我似乎不能正确地运用我的头脑

我有记录

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+subminbtns-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.
for i:=0 to X do
begin
  tempButton := TsSpeedButton.Create(nil);
  Main[i] := tempButton;
  //whatever else
end;
然而,这段代码甚至不能被编译,所以我正在寻求一种可行的方法来完成我试图做的事情

首先,“这个”是C++,不是Pascal。Delphi版本是“Self”。第二,不能按名称引用带有ed的对象。最好不要对使用
。试着这样做:

for i:=0 to X do
with TsSpeedButton.Create(nil) do begin
Main[i] := this; //where this is the created sSpeedButton.
for i:=0 to X do
begin
  tempButton := TsSpeedButton.Create(nil);
  Main[i] := tempButton;
  //whatever else
end;

嗯,我找到了一个更有效的方法来实现这一点,但我感谢你的回答。接受:)好啊那么出于好奇,你有什么更好的方法?