[Lazarus] Filling ListBox without triggering OnSelectionChange

Marc Santhoff M.Santhoff at web.de
Fri Jan 9 12:30:55 CET 2015

On Fr, 2015-01-09 at 11:00 +0100, Bart wrote:
> On 1/9/15, Marc Santhoff <M.Santhoff at web.de> wrote:
> > Yes, but if it is done in Form.OnCreate is is (here).
> No, it does not (with fpc 2.6.4/win32)

I'll see next time my Lazarus is updated. If the current version works
with fpc 2.6.2 that could happen immeadiately.

> Workaround would be like:
> procedure TForm1.FormCreate(Sender: TObject);
> var
>   i: longword;
> begin
>   tasklist := TStringList.create;
>   for i:=0 to taskmax do tasklist.add(tasks[i]);
>   ListBox1.OnSelectionChange := nil;
>   ListBox1.Items.Assign(tasklist);
>   ListBox1.OnSelectionChange := @ListBox1SelectionChange;
> end;

Tried that solution already, but it does not help. There must be
something special later in the form creation chain, that forces
selection on the listbox and in turn trigger SelectionChange.

If the assignment of OnSelectionChange hanlder is done a bit later, in
FormShow that is, it works as expected.

Maybe something else regarding the creation of forms has changed inside
LCL between Lazarus 1.2 and 1.3.

> If the InvokeAction only is supposed to be as a respons to the user
> clicking, you could also check the User parameter.

Will do.

Marc Santhoff <M.Santhoff at web.de>

More information about the Lazarus mailing list