[Lazarus] Filling ListBox without triggering OnSelectionChange

Bart bartjunk64 at gmail.com
Fri Jan 9 11:00:17 CET 2015


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)

> Here we go:
> fpc 2.6.2
> Lazarus 1.2.0, x86_64-gtk2
> FreeBSD 9 amd64

So, might be WS related.


>   tasks: array [0..taskmax] of string = (
>     'Tudies',
>     'Tudas',
>     'Sonstwas'
>     );
>
> implementation
>
> procedure TForm1.FormCreate(Sender: TObject);
> var
>   i: longword;
> begin
>   tasklist := TStringList.create;
>   for i:=0 to taskmax do tasklist.add(tasks[i]);
>   ListBox1.Items.Assign(tasklist);
> end;
>

Tried that, no OnSelectionChange.

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;

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

Bart




More information about the Lazarus mailing list