[Lazarus] Filling ListBox without triggering OnSelectionChange

Marc Santhoff M.Santhoff at web.de
Fri Jan 9 09:30:19 CET 2015


On Do, 2015-01-08 at 11:40 +0100, Bart wrote:
> On 1/7/15, Marc Santhoff <M.Santhoff at web.de> wrote:
> > Hi,
> >
> > it has been a very long time since I've programmed GUIs. I have
> > forgotten how to fill a ListBox without having the event handler
> > OnSelectionChange executed.
> 
> When I fill a listbox with items, there is no OnSelectionChange executed at all.
> Lazarus 1.3, win32.

Yes, but if it is done in Form.OnCreate is is (here).

> Please show us the code you used to fill the listbox.
> Also please provide Lazars version and widgetset.

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

I have simply made a new gui project, put some components on the form
and assigned the jhandlers by double clicking the object inspectors
event field.

Then I wrote this code:

<snip>

const
  taskmax = 2;

  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;

procedure TForm1.ListBox1SelectionChange(Sender: TObject; User:
boolean);
begin
  if (Sender <> NIL) then begin
    InvokeAction(tasks[(Sender as TListBox).ItemIndex]);
  end;
end;

</snip>

InvokeAction() is a method of the same form and does get triggered when
I start the program, having the form in question as its main form. The
first Item in the list is selected.


-- 
Marc Santhoff <M.Santhoff at web.de>





More information about the Lazarus mailing list