2009-08-04 9 views
2

質問が愚かに見える場合は申し訳ありませんが、最後の時間に頭を正しく使用できないようです。私はレコードを持っている実行時に作成されたボタンを配列に追加する方法は?

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; 

が私のためにループ」にフォーカスできるようにします:= 0 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. 

Howeve、このコードにもコンパイルすることができないので、私は私が何をしようとしている達成するためになんとか方法を求めています。

ありがとうございます。

答えて

3

まず「this」はパスカルではなくC++です。 Delphiのバージョンは "Self"です。第2に、with-edオブジェクトを名前で参照することはできません。あなたはwithを一切使わない方が良いでしょう。

for i:=0 to X do 
begin 
    tempButton := TsSpeedButton.Create(nil); 
    Main[i] := tempButton; 
    //whatever else 
end; 
+0

私はこれを達成するより効率的な方法を見つけましたが、私はあなたの答えをありがとう。 :) –

+0

OK。あなたの好きなやり方は何ですか?ただ好奇心から出ますか? –

関連する問題