[Lazarus] Assigning Class to object

Steve Gatenby steveg at nevets.com.au
Mon Dec 6 00:36:28 CET 2021


Please dont judge on simplicity of question (or questioner) -  :)

if I call the following procedure with either a TButton or Panel ctrl 
(for example), how can I use the class info contained within the MyObj 
to choose the correct Class

procedure SetThis( MyObj :TObject );
begin

   // this works -
   if pos('Button', MyObj.ClassName) > 0
   then TButton(MyObj).OnMouseDown := tmethod (not important here)
   else TButton(MyObj).OnMouseDown := tmethod; (not important here)

   // what I would like is the single assignment as could cover multiple 
controls / events
   TClass(MyObj).OnMouseDown := tmethod (not important here)

end;

Regards SteveG



More information about the lazarus mailing list