In your settings form you want something like this (simplified)
TSettingsForm = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
public
function GetEditText(anID: PtrInt): String;
end;
var
SettingsForm: TSettingsForm;
implementation
function TSettingsForm.GetEditText(anID: PtrInt): String;
var
c: Integer;
begin
for c := 0 to ControlCount-1 do
if (Controls[c] is TEdit) and (Controls[c].Tag = anID) then
Exit(TEdit(Controls[c]).Text);
Result := '';
end;
In your main form, you want a single buttonclick handler assigned to all the form's buttons something along these lines (again simplified to the essentials):
TFormMain = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure ButtonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
end;
procedure LaunchApp(anAppName: String);
var
FormMain: TFormMain;
implementation
uses
uSettingsForm;
procedure LaunchApp(anAppName: String);
begin
case LowerCase(anAppName) of
'explorer': ; // your code goes here
'word': ;
'doom': ;
else ShowMessageFmt('The application "%s" is invalid', [anAppName]);
end;
end;
procedure TFormMain.ButtonClick(Sender: TObject);
var
appName: String;
btn: TButton absolute Sender;
begin
if (Sender is TButton) then
begin
appName := Trim(SettingsForm.GetEditText(btn.Tag));
if appName <> '' then
LaunchApp(appName);
end;
end;
procedure TFormMain.FormShow(Sender: TObject);
begin
SettingsForm.Show;
end;
You have to ensure, of course, that the each button's Tag corresponds to the correct TEdit.Tag on the settings form, and that each Tag is unique.
A more complex way to ensure such correct correspondence would be to create both buttons and edits dynamically using dynamic arrays of components, when you can forget the tag and just use an array index. But this is hardly justified for a simple app, since it means writing quite a lot more code, and using the Tag property works well. For some reason there are programmers who frown on using Tag for this. I've never understood why, since it was clearly one reason why Borland introduced such a universal component property.