Title: How to form reference with string name.
Question: I want to use dynamic form, but I want to reference it by name and find form before create it.
How I do?
Answer:
function MDIisOpen(MainForm: TForm; MDIFormName: String): Boolean;
var i: Integer;
begin
for i:=0 to Pred(MainForm.MDIChildCount) do begin
if lowercase(MainForm.MDIChildren[i].Name)=lowercase(MDIFormName) then
begin
MainForm.MDIChildren[i].Show;
MainForm.MDIChildren[i].BringToFront;
Result := True;
Break;
end;
end;
end;
procedure OpenMDIForm(Sender: TObject; SClass: TformClass; Maxi: Boolean);
var fmForm : TForm;
fmClassRef : TFormClass;
SenderName : String;
c_name: String;
begin
c_name := SClass.ClassName;
GrantAccess := GetLoginProperty(FDMU.User_Login.FieldByName('prog_st').AsString,c_name);
if GrantAccess='' then begin
beep;
MessageDlg('non authorize access for this programs.',mtInformation,[mbok],0);
exit;
end;
if not MDIisOpen(MDIAppMainF,copy(c_name,2,length(c_name))) then begin
fmClassRef:=SClass;
fmForm := fmClassRef.Create(MDIAppMainF);
if Sendernil then SenderName := Sender.ClassName;
if SenderName='TAction' then fmForm.Caption := TAction(Sender).Caption;
if Maxi then fmForm.WindowState := wsMaximized;
fmForm.Show;
end;
end;