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