Cant Make Dynamic Buttons Click Work Please Help lazarus / 10-Designer ---------------------------------------------------------------------- itsarmin · 2015-09-23 21:38 Hi. im so new, I'm Trying to create dynamic buttons(they read their name from stringlist:Textfile ) and i got it work, but ONCLICK event i cant make it work to read from another line in that text file and apply it to a Memo.caption . procedure Tfrm_addnew.btn_NewOkClick(Sender: TObject); var   TheNumber:integer;   i:integer;   Str:Tstringlist;   Btns:Array [1..100] of TButton; begin //Get The Number------   Str:=TStringList.Create;   Str.LoadFromFile('infor.txt');   TheNumber:=(str.Count-2)div 2; //Creat Buttons------- for i:=1 to TheNumber do   begin     btns:=TButton.Create(Self);     with Btns do       begin         Parent:=frm_Databox.ScrBox;         Height:=20;         Width:=99;         Top:=20*i-20;         Caption:=str.ValueFromIndex[i*2];         OnClick:=Thebox.frm_Databox.Note.Caption:=str.ValueFromIndex[i*2];        end;   end;   Str.free; close; end; ---------------------------------------------------------------------- derek.john.evans · 2015-09-23 21:53 OnClick must be set to the address of a TNotifyEvent compatible method: ie: TNotifyEvent is defined as: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TNotifyEvent = procedure(Sender: TObject) of object; Therefore your method must be: (Note: The method name can be changed) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Tfrm_addnew.ButtonClick(Sender: TObject);beginend;  Then link the OnClick event to the TButton using: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i btns.OnClick := @ButtonClick;// Or, for Delphi mode, use: (Note: In Delphi mode the @ isn't required)btns.OnClick := ButtonClick;  http://wiki.freepascal.org/TButton There are a lot of different event types, so its common practice to use the popupmenu tool"Find declaration of ???? ...", and then copy/paste the event prototype into your class. ** EDIT ** TButtons have a Tag property which you can use to store the Index (Which must me set in your for loop). You can get the button that was clicked using (Sender as TButton), and therefore you can get the Index of the button using (Sender as TButton).Tag. ---------------------------------------------------------------------- itsarmin · 2015-09-23 23:20 Thank you so much, tag and @ was really helpful now The only problem is that , i don't know what is the name of the buttons that are being created dynamically it gives me error , please help me with this I'm Uploading the project, I know its to much to ask, but maybe you or someone can take a look at it. Thank you so much ---------------------------------------------------------------------- derek.john.evans · 2015-09-23 23:37 Line: 45 // should be: Code: [Select]procedure Tfrm_addnew.BtnsClick(Sender: TObject);    Line: 52 // should be: Code: [Select]a:=(Sender as TButton).tag*2+1; ---------------------------------------------------------------------- itsarmin · 2015-09-24 14:30 Awesome , Thank you so much for helping me . all working good .