March 10th, 2013, 02:12 PM
Handling runtime objects
Iím trying to write a program in Delphi in which you can type some text in an edit box, then press the button next to it to make a memobox containing the text you just typed and a deletebutton next to it. The delete button should delete both itself and the memobox next to it. This means that both the memo box and the delete button will be made in runtime. The problem I have is finding a way to handle each button individually. Here is the code I already have:
procedure TForm1.btn_createClick(Sender: TObject);
NewMemo : TMemo;
NewButton : TButton;
namearray:Array of string;
with NewMemo do
Width := 120;
Top:= 55 + 12*(self.ControlCount-2);
with NewButton do
procedure TForm1.CustomButtonclick(Sender: TObject);
if Self.ControlCount>2 then
Right now, I have only gotten the delete button to delete the last two items that were created, but I would like the button to only delete itself and the memo next to it (preferably by checking the components name, which I canít seem to get working). Any help would be greatly appreciated.
March 11th, 2013, 06:12 PM
Seems like a very poor design approach. Is there a reason you do not use either a messageDlg or simply create and free a custom form?
If you have to use this approach, I suggest you move the memo and button variables to the private section of the form and simply create and free them as needed (I am assuming you do not create more than one instance at a time).
March 12th, 2013, 07:21 PM
I'm very new to delphi, so I wasn't sure if this method is possible or not.
There is only one instance running at a time. I will look into the messageDlg method. Thank you for your help.
March 26th, 2013, 01:03 PM
NEVER use this:
1 - NEVER use "DESTROY" directly. Use Free!
2 - NEVER use "destroying" one component into its EVENT HANDLERS
3 - When make a component in runtime, you can to use CREATE(Owner) (if possible) with param :
xxx:= TButton.Create( "Self" or "TForm" or another container );
So, the "OWNER" (the param) will be who delete the new component when the OWNER is deleted.
See the help in Delphi for parameters in CREATE() function.
See: SELF, NIL, (another component)
Container, are that as: Forms, Frames, DataModules, Panels, etc...