I\'m working with Delphi 7 and I\'m trying to create a form programmatically. Here\'s my form class stub:
unit clsTStudentInfoForm;
interface
uses Form
Creating modal forms with controls on the fly is easy:
procedure CreateGreetingForm;
var
frm: TForm;
lbl: TLabel;
edt: TEdit;
btn: TButton;
begin
frm := TForm.Create(nil);
try
lbl := TLabel.Create(frm);
edt := TEdit.Create(frm);
btn := TButton.Create(frm);
frm.BorderStyle := bsDialog;
frm.Caption := 'Welcome';
frm.Width := 300;
frm.Position := poScreenCenter;
lbl.Parent := frm;
lbl.Top := 8;
lbl.Left := 8;
lbl.Caption := 'Please enter your name:';
edt.Parent := frm;
edt.Top := lbl.Top + lbl.Height + 8;
edt.Left := 8;
edt.Width := 200;
btn.Parent := frm;
btn.Caption := 'OK';
btn.Default := true;
btn.ModalResult := mrOk;
btn.Top := edt.Top + edt.Height + 8;
btn.Left := edt.Left + edt.Width - btn.Width;
frm.ClientHeight := btn.Top + btn.Height + 8;
frm.ClientWidth := edt.Left + edt.Width + 8;
if frm.ShowModal = mrOk then
ShowMessageFmt('Welcome, %s', [edt.Text]);
finally
frm.Free;
end;
end;