Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have TButtons which the user can create at runtime. When they are created the button is added to its own TObjectlist depending on which button they create. I believe the list stores all the properties of the button. The first code is where the button is created and added to its own TObjectlist. I have tried using the buttons tag as the index location in the list and deleting it but that doesn't seem to work.
(I know it doesn't work because I can save the location and then load it. If it worked then when deleting the button and saving, loading it would show nothing).

What I have tried:

Function TForm1.Createbutton1(Number: Integer):TButton;
var
  button1 : TButton;
begin
  button1 := TButton.Create(nil);
  try
    button1.Parent := Self;
    button1.Caption := ('Button1');
    button1.Tag := Number;
    button1.Top := 100;
    button1.Left := 100;;
    button1.Width := 145;
    button1.Height := 25;
    button1.OnMouseDown := ButtonMouseDown;
    button1.OnMouseMove := ButtonMouseMove;
    button1.OnMouseUp := ButtonMouseUp;
    button1s.Add(button1);
  except
    button1.Free;
    raise;
  end;
  Result := button1;
end;


Procedure TForm1.ButtonRightMouseDown(Sender: TObject; Button : TMouseButton);
var
ButtonTag : Integer;
begin
 if Button = mbRight then
  Begin
  if (Sender as TButton).Caption = 'Button1' then
  begin
  ButtonTag := (Sender as TButton).Tag;
  Button1s.Delete(ButtonTag);
  end;
  PostMessage( Form1.WindowHandle, WM_DELETE_CONTROL, WPARAM( Sender ), 0 ); 
  FTableButtonDragging := False; 

  end;

end;
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900