[Lazarus] Filling ListBox without triggering OnSelectionChange

Michael Thompson mike.cornflake at gmail.com
Thu Jan 8 02:50:44 CET 2015

On Thu Jan 08 2015 at 9:08:26 AM Marc Santhoff <M.Santhoff at web.de> wrote:

> Yes, assigning the event handler does work, if it is done in OnActivate.

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...

procedure TForm1.FormActivate(Sender: TObject);
  if not ListBox1Initialised then
    ListBox1.ItemIndex := -1;
    ListBox1.OnSelectionChange := @ListBox1SelectionChange;
    ListBox1Initialised := True;  // and set this to false in FormCreate

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150108/75aff608/attachment-0003.html>

More information about the Lazarus mailing list