1

i use dynamic array in delphi.

var

var
  frame3:array[0..10] of TFrame3
procedure TForm1.Button1Click(sender:TObject);
begin
    frame3[count] := TFrame3.create(self);
    gridpanel2.insertcontrol(frame3[count]);

but this code is 'A component named Frame3 alredy exists.' this error what can ido?

1
  • 1
    That's not a dynamic array. I think the key to this though can be found in TFrame3. Commented Nov 2, 2015 at 7:00

2 Answers 2

3

If you need multible instances of TFrame3 you need to give it a new name after you created it.

so change

 frame3[count] := TFrame3.create(self);
 gridpanel2.insertcontrol(frame3[count]);

To

 frame3[count] := TFrame3.create(self);
 frame3[count].Name := 'Frame3_' + InttoStr(Count);
 gridpanel2.insertcontrol(frame3[count]);
Sign up to request clarification or add additional context in comments.

1 Comment

or just remove name at all
1

The other issue is that it is not seen in your code how you are changing count loop variable. Is it defined in advance?

You need to do something like this:

procedure TForm1.Button1Click(sender:TObject);
var count:byte;
begin
  for count:=1 to 10 do
    begin
      frame3[count] := TFrame3.create(self);
      ...
    end;

or use any other way to set count before each array member (class instance) creation. This code will even probably not require to set Name property at all.

1 Comment

The name is set by default, so you have to rename each frame instance

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.