How to add code inside the event of a component? lazarus / 8-Other ---------------------------------------------------------------------- cyber_python · 2008-04-23 14:16 Hello, I am trying to create a descendant of TTreeview that behaves like this: When a node expands (TTreeview.OnExpanding event) a certain procedure is called (the procedure adds children nodes to the child nodes). Does anyone know how can I do this? ---------------------------------------------------------------------- Leledumbo · 2008-04-24 03:16 Can't you just assign a method to it? Code: [Select] type   TMyTreeView = class(TTreeView)   private     procedure AddChildrenNodesToChildNodes(Sender: TObject;       Node: TTreeNode; var AllowExpansion: Boolean);   end; ... // for instance, assign it in constructor constructor TMyTreeView.Create; begin   FOnExpanding:=@AddChildrenNodesToChildNodes; end; ---------------------------------------------------------------------- cyber_python · 2008-04-24 07:59 Thank you very much Leledumbo! It worked fine. I thought that doing it this way, if a user tried to add some code to the event at design time, his code would replace my code instead of it being executed after mine. Anoter question : How can I add a TStrings property to my component ? I have added a private variable:   a : TStrings; a procedure to set it :   procedure SetA(const newA: TStrings);   procedure TMyTreeview.SetA(const newA: TStrings);   begin         if (newA <> nil) then         begin               a.Assign(newA);                   end;   end; and a published property :    property myProperty: TStrings read a write SetA; in the constructor :   a := TStringList.Create; and in the destructor :   FreeThenNil(a);   inherited Destroy; but when I try to add some strings(by clicking the button with the dots) at design time I get an error ('Access violation'). I checked the implementation of TCustomMemo and it was pretty similar to my code. Any ideas? ---------------------------------------------------------------------- Marc · 2008-04-24 14:44 Usually there is a virtual method just calling the event. Something like DoOnExpanding; You can override that to add your own code. To find out you can set a breakpoint in your handler and  check where it got called. ---------------------------------------------------------------------- cyber_python · 2008-04-25 12:35 Thanks Marc! I used the DoPaintNode procedure and it works fine! I also solved the problem with the access violation (I had forgotten to erase a line that was reffering to a TStringList that I do not create anymore....) But, now I have a new question : When I assign a StringList to my Component's TStrings property it works fine (e.g. MyTreeview.a := str;  where str is a TStringList), but when I edit the property at design time (with the Lazarus Strings editor) the procedure I have specified for writing the property does not seem to  get executed. I say it seems because I added the following code to the form's onCreate event and now the treeview items got updated (str is a TStringList) :  str := TStringList.create;  str.assign(MyTreeview.a);  MyTreeview.a:=str;  str.free; Thank you in advance, cyber_python. ***Update : I just noticed that some integer properties (that have their own procedures to set the value) that I have added do not work at design time as well, so it must not have to do with TStrings.