2

I'm sorry if the question looks stupid,but It seems I can't use my head properly in the last hours.

I have a record,

type
  TMain = record
    Sub:Array of TSubMain; //another record
    Button:TsSpeedButton; //this is what we need!
  end;

a variable

 Main:Array of TMain;

and function:

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;

Lets focus on the loop 'for i := 0 to MainBtns + subMainBtns - 1'.I'd like to add the button created below to the array created above named 'Main:Array of Tmain'.

It should look like this:

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

Howeve,this code can't even be compiled,so I'm asking for a doable way to accomplish what I'm trying to do.

Thank you.

1 Answer 1

3

First off, "this" is C++, not Pascal. The Delphi version is "Self". Second, you can't refer to the with-ed object by name. You're better off not using with at all. Try something like this:

for i:=0 to X do
begin
  tempButton := TsSpeedButton.Create(nil);
  Main[i] := tempButton;
  //whatever else
end;
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm I found a much more efficient way to accomplish this,but I appreciate your answer.Accepted. :)
OK. So what's your better way, just out of curiosity?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.