BRowley
asked on
Example of MRU in ComboBox
HI
Im making an app that can log onto different servers but only one at once. I would like it that when the app loads it can read the registry and grab a list of servers that have been used before and put them into a combobox OR if they enter a new name it stores it into the registry with the others.
I have looked at some components but they all seem to be with files and not entries in a registry like i need.
Example will get the points.
Many thanks
B.
Im making an app that can log onto different servers but only one at once. I would like it that when the app loads it can read the registry and grab a list of servers that have been used before and put them into a combobox OR if they enter a new name it stores it into the registry with the others.
I have looked at some components but they all seem to be with files and not entries in a registry like i need.
Example will get the points.
Many thanks
B.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. Dont suppose you know how to stop the beep on enter on the combobox do you please?
Anyway many thanks for your time and help.
Regards
Barry
Anyway many thanks for your time and help.
Regards
Barry
Thank for the points, Barry.
About beep:
procedure TForm1.ComboBox1KeyPress(S ender: TObject; var Key: Char);
...
ComboBox1.Items.Add(ComboB ox1.Text);
Key := #0; // add this line to suppress the beep
...
end;
Regards, Geo
About beep:
procedure TForm1.ComboBox1KeyPress(S
...
ComboBox1.Items.Add(ComboB
Key := #0; // add this line to suppress the beep
...
end;
Regards, Geo
Actually, it'd be better to place that line (Key := #0;)immediately after:
if Key = #13 then begin // Enter key
That way all beeps will be ignored. In my previous comment only the beeps when adding new items are suppressed.
Regards, Geo
if Key = #13 then begin // Enter key
That way all beeps will be ignored. In my previous comment only the beeps when adding new items are suppressed.
Regards, Geo
ASKER
Thank you.
regards
B.
regards
B.
Form.OnCreate loads server names from HKEY_CURRENT_USER\Software
ComboBox1.OnKeyPress adds a new server name entered in the combobox.
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
KeyPath: string = 'Software\Geobul\Servers';
ValueNames: TStringList;
implementation
{$R *.DFM}
uses Registry;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
with TRegistry.Create do begin
// HKEY_CURRENT_USER by default
if OpenKey(KeyPath, false) then begin
ValueNames := TStringList.Create;
try
ComboBox1.Items.Clear;
GetValueNames(ValueNames);
for i := 0 to ValueNames.Count - 1 do begin
ComboBox1.Items.Add(ReadSt
end;
finally
ValueNames.Free;
end;
CloseKey;
end;
Free;
end;
end;
procedure TForm1.ComboBox1KeyPress(S
begin
if Key = #13 then begin // Enter key
if ComboBox1.Items.IndexOf(Co
with TRegistry.Create do begin
if OpenKey(KeyPath, true) then begin
WriteString('Server'+ IntToStr(ComboBox1.Items.C
ComboBox1.Items.Add(ComboB
end;
end;
end;
end;
end;
Regards, Geo