Board index » delphi » newbie- adding shape component at runtime?

newbie- adding shape component at runtime?

How would I add a shape component to a form at run time?

Thanks for any help.

please email: micha...@oasys.dt.navy.mil

Rob M.

 

Re:newbie- adding shape component at runtime?


Quote
michaels wrote:

> How would I add a shape component to a form at run time?

1) First, manually declare a variable of type TShape anywhere, possibly
   inside the "public" section of your TForm.  Such as...

      myShape: TShape;

2) Next, Create the shape, then set its properties.  Such as...

      begin
           ...
           myShape := TShape.Create(Form1);
           with myShape do
              begin
              Parent := Form1;
              Top := 10;
              Left := 10;
              Brush.Color := clRed;
              end;
           ...
      end;

If you want to create more than 1 TShape, I suggest you use/create an
array of TShapes. Like:

      var
         myShapes: array [1..100] of TShape;
         i: Integer;
      begin
           ...
           for i := 1 to 100 do
              begin
              myShapes[i] := TShape.Create(Form1);
              with myShapes[i] do
                 begin
                 Parent := Form1;
                 {...etc...}
                 end;
           ...
       end;

Hope this helps,
-Jim Rofkar.

Other Threads