Board index » delphi » Adding new TShapes to a form ?

Adding new TShapes to a form ?

This is probably a dumb question, but I'm tired and guess I'm missing
something silly.

I need to add a varying number of TShape components to a form, I
have an array:

tsh : array[1..10] of  TShape;

then do:

for i:=1 to 10 do begin
  tsh[i]:=TShape.create(Self);
  set misc component values like color etc here
end;

but of course these are all invisible.

How can I create a new TShape and have it visible on the current form?

Thanks,

Roy.

 

Re:Adding new TShapes to a form ?


Quote
Roy Coates <r...@mechnet.liv.ac.uk> wrote in message

news:7ukvb6$d0b$1@news.liv.ac.uk...

Quote
> This is probably a dumb question, but I'm tired and guess I'm missing
> something silly.

> I need to add a varying number of TShape components to a form, I
> have an array:

> tsh : array[1..10] of  TShape;

> then do:

> for i:=1 to 10 do begin
>   tsh[i]:=TShape.create(Self);
>   set misc component values like color etc here
> end;

> but of course these are all invisible.

> How can I create a new TShape and have it visible on the current form?

...If it descends from TControl, it needs a parent.

  for i:= Low(tsh) to High(tsh) do begin
    tsh[i]:=TShape.create(Self);
    tsh[i].Parent := Self;
    set misc component values like color etc here
  end;

(This code also won't break if you change the size of the
array).
--
Jeremy Collins
Kansai Business Systems
http://www.kansai.co.uk/

Re:Adding new TShapes to a form ?


D'oh...  I forgot the .parent attrib.

My apologies.. I really /must/ get some sleep!

Other Threads