Page 1 of 1

Add / Remove TRectangle Tools during RunTime

Posted: Mon Sep 11, 2006 6:52 am
by 9346574
Please help me... Its urgent

We are developing a VCL Component.
In the constructor I'm creating a Rectangle tool like:

EditTextTool : TRectangleTool;
self.EditTextTool := TRectangleTool.Create(self);

While dragging the component from the pallete(during design time), the constructor is being called and the tool was created.

When we run the application, the constructor is called again, and one more tool was created.

How can I find any existing tools and remove them, before creating new ones...???

Posted: Tue Sep 12, 2006 9:04 am
by narcis
Hi Krishna,

You can try doing something like this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  RectTool: TRectangleTool;
  i: Integer;
begin
  if Chart1.Tools.Count > 0 then
    for i:=Chart1.Tools.Count-1 downto 0 do
      if (Chart1.Tools[i] is TRectangleTool) then
        Chart1.Tools[i].Free;

  RectTool:=TRectangleTool.Create(self);
  Chart1.Tools.Add(RectTool);
end;