I wonder if there is some way to create TShape controls programmatically during runtime. For example, insteed of putting 100 shapes, hide them and when the program runs, show them, 100 shapes could be created over some time (5 shapes created in 5 seconds, 10 in 10 seconds, 15 in 15 seconds, and so on).
-
Something like: procedure TForm.Timer1Timer(Sender: TObject); begin With Tshape.Create(self) do begin Parent := self; Left := xxx end; end; ??bummi– bummi2013-04-27 10:38:18 +00:00Commented Apr 27, 2013 at 10:38
-
Yes, something like thatuser2296565– user22965652013-04-27 11:35:18 +00:00Commented Apr 27, 2013 at 11:35
-
GExperts and CnWizards have button to convert any visual component into code. Perhaps such questions "how make VCL components a code" are all be considered duplicate...Arioch 'The– Arioch 'The2013-04-29 13:28:01 +00:00Commented Apr 29, 2013 at 13:28
Add a comment
|
1 Answer
You should not draw and animate by using controls. Instead, you should draw manually using plain GDI or some other API. For an example, see this example or this example from one of your questions.
Anyhow, a simple answer to your question: Put a TTimer on your form and set its Interval to 250, and write:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
FShapes: array of TShape;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
SetLength(FShapes, Length(FShapes) + 1); // Ugly!
FShapes[high(FShapes)] := TShape.Create(Self);
FShapes[high(FShapes)].Parent := Self;
FShapes[high(FShapes)].Width := Random(100);
FShapes[high(FShapes)].Height := Random(100);
FShapes[high(FShapes)].Left := Random(Width - FShapes[high(FShapes)].Width);
FShapes[high(FShapes)].Top := Random(Height - FShapes[high(FShapes)].Height);
FShapes[high(FShapes)].Brush.Color := RGB(Random(255), Random(255), Random(255));
FShapes[high(FShapes)].Shape := TShapeType(random(ord(high(TShapeType))))
end;
end.
1 Comment
Andreas Rejbrand
@user2296565: It's all there. It's a private field of the form class.