Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating new instances at runtime.

Status
Not open for further replies.

Brollo

Programmer
Jan 19, 2004
2
BE
I want to create an application which places shapes (circles) on a panel everytime I click the mouse.
Is there a way to create new instances of this shape component without affecting the position of the original component ?
TIA;
 
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with TShape.Create(Self) do
begin
Parent:=Panel1;

Shape:=ReferenceShape.Shape;
Brush:=ReferenceShape.Brush;
{Copy/set other properties as required}

Left:=X-Panel1.Left-Self.Left;
Top:=Y-Panel1.Top-Self.Top;
{not sure I've got Left/Top correct, but you get the idea <g>}
end;
end;

By making the owner the form (self) the new shape will be freed by the form when the form is freed.

Have fun
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top