<div class="gmail_quote">On Thu Jan 08 2015 at 9:08:26 AM Marc Santhoff <<a href="mailto:M.Santhoff@web.de">M.Santhoff@web.de</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, assigning the event handler does work, if it is done in OnActivate.<br></blockquote><div><br></div><div>I'm sure you're aware of this, but just in case:  Form.OnActivate should fire each time your user switches between forms in your UI.  I usually put similar code inside a boolean flag to ensure the code only runs once at initialisation.  Even if it's not immediately required, having it there will help if you later call an open/save dialog or similar from that form...</div><div><br></div><div><span style="line-height:19.7999992370605px">procedure TForm1.FormActivate(Sender: TObject);</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">begin</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">  if not ListBox1Initialised then</span></div><div><span style="line-height:19.7999992370605px">  begin  </span></div><div><span style="line-height:19.7999992370605px">    ListBox1.ItemIndex := -1;</span><br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">    ListBox1.OnSelectionChange := @ListBox1SelectionChange;</span></div><div><span style="line-height:19.7999992370605px">    </span><span style="line-height:19.7999992370605px">ListBox1Initialised</span><span style="line-height:19.7999992370605px"> := True;  // and set this to false in FormCreate</span></div><div>  end;<br style="line-height:19.7999992370605px"><span style="line-height:19.7999992370605px">end;</span><br></div><div><span style="line-height:19.7999992370605px"><br></span></div><div><span style="line-height:19.7999992370605px">Mike</span></div></div>