[lazarus] Run-time generated combo-boxes.
Mattias Gaertner
nc-gaertnma at netcologne.de
Fri Apr 11 04:47:37 EDT 2003
On 11 Apr 2003 09:39:48 +0200
"A.J. Venter" <ajventer at direqlearn.org> wrote:
> Hi,
> For my administration interface, I have two sections (password changing
> and user deletion) where the user can select a username from a combobox.
> I wrote a procedure called fillUserList, which when run will read
> /etc/passwd, drop system users (below UID 500) and place the rest into a
> the combobox, then this list needs to become the contents of the
> combobox. It has to be redone whenever the user goes to the relevant
> section, because the list can and will change during operation, e.g. a
> user may be deleted and another's password have to be changed.
>
> Everything works like that, but the catch is when to run it. Right now I
> have it linked to the comboBox's onDropDown event, but this is not
> working. The first time you open the list, only the first user appears,
> only if you close and reopen it, does the full list show up.
Fixed.
Mattias
> How do I do this ?
>
> The code looks like this:
>
> procedure TForm4.FillUserList;
> Var AllUsers : Tstrings;
> Users : Tstrings;
> S : String;
> CNT : Integer;
> begin
>
> {ComboPop is a boolean, used to keep track of whether the comboBox has
> allready been populated on this run, it is reset to false when the form
> closes}
> If not ComBoPop then
> Begin
> AllUsers := tStringlist.Create;
> Users := tstringList.Create;
> AllUsers.LoadFromFile ('/etc/passwd');
> For CNT := 0 to AllUsers.Count -1
> Do
> Begin
> S := Allusers[cnt];
> Delete(S,1,pos(':',S));
> Delete(S,1,pos(':',S));
> S := Copy(S,1,pos(':',S) - 1);
> If (StrToInt(S) >= 500) AND
> (Copy(AllUsers[cnt],1,pos(':',AllUsers[cnt]) -1) <> 'admin') then
> Users.Add(Copy(AllUsers[cnt],1,pos(':',AllUsers[cnt]) -1));
>
> end;
>
> Form4.ComboBox1.Items.Assign(Users);
> AllUsers.Free;
> Users.Free;
> end;
>
> end;
>
> --
> Story of my life: "Semper in excretum, set alta variant"
> A.J. Venter
> DireqLearn Linux Guru
>
> _________________________________________________________________
> To unsubscribe: mail lazarus-request at miraclec.com with
> "unsubscribe" as the Subject
> archives at http://www.lazarus.freepascal.org/mailarchives
More information about the Lazarus
mailing list