N.Marzio Posted May 13, 2020 Share Posted May 13, 2020 How can I open a form from a string? Tks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 13, 2020 Share Posted May 13, 2020 3 minutes ago, N.Marzio said: How can I open a form from a string? Hello, Can you please explain in more detail? Quote Link to comment Share on other sites More sharing options...
N.Marzio Posted May 13, 2020 Author Share Posted May 13, 2020 From the mainform I would like to open a secondary form procedure ShowMyForm(aformName : string); begin ???????? end; procedure TxFrmBase.UniButton1Click(Sender: TObject); begin ShowMyForm('TxFrmBase '); end; My Sencond Form TxFrmBase = class(TUniForm) procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } .... .... public { Public declarations } ...... end; function xFrmBase: TxFrmBase; begin Result := TxFrmBase(UniMainModule.GetFormInstance(TxFrmBase)); end; Tks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 13, 2020 Share Posted May 13, 2020 You can use FindClass() function. Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted May 14, 2020 Share Posted May 14, 2020 hi, Self.Name; Quote Link to comment Share on other sites More sharing options...
N.Marzio Posted May 14, 2020 Author Share Posted May 14, 2020 sorry, but with findClass (), I couldn't get it to work .... Do you have an example? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 14, 2020 Share Posted May 14, 2020 with TUniFormClass(FindClass('TxFrmBase')).Create(UniApplication) do Show(); procedure TMainForm.UniFormCreate(Sender: TObject); begin RegisterClass(TxFrmBase); ... end; Quote Link to comment Share on other sites More sharing options...
N.Marzio Posted May 14, 2020 Author Share Posted May 14, 2020 I had already tried, but it doesn't work ... Error Class not Found... Quote Link to comment Share on other sites More sharing options...
N.Marzio Posted May 15, 2020 Author Share Posted May 15, 2020 I solved. Thanks Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted May 15, 2020 Share Posted May 15, 2020 12 hours ago, N.Marzio said: Eu resolvi. obrigado Show how you managed to solve please !! Quote Link to comment Share on other sites More sharing options...
Mehmet Emin Posted May 15, 2020 Share Posted May 15, 2020 Probably calling in initialization will do it initialization RegisterClass(TxFrmBase); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 15, 2020 Share Posted May 15, 2020 4 minutes ago, Mehmet Emin said: Probably calling in initialization will do it Also in FormCreate: On 5/14/2020 at 5:39 PM, Sherzod said: procedure TMainForm.UniFormCreate(Sender: TObject); begin RegisterClass(TxFrmBase); ... end; Quote Link to comment Share on other sites More sharing options...
N.Marzio Posted May 15, 2020 Author Share Posted May 15, 2020 TxFrmBase = class(TUniForm) procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } // public { Public declarations } end; TFrmBase = class of TxFrmBase; Initialization RegisterClass(TxFrmBase ); TMainForm = class(TUniForm) procedure onClick(Sender : TObect); private function FindAnyClass(const aName: string): TClass; procedure showMyForm(aMyForm : string); public end; function TMainForm.FindAnyClass(const aName: string): TClass; var ctx: TRttiContext; typ: TRttiType; list: TArray<TRttiType>; begin Result := nil; // if Trim(aName) = '' then exit; // ctx := TRttiContext.Create; list := ctx.GetTypes; for typ in list do begin if typ.IsInstance and (EndsText(aName, typ.Name)) then begin Result := typ.AsInstance.MetaClassType; break; end; end; ctx.Free; end; procedure TMainForm.showMyForm(aMyForm : string); var lTag : TFrmBase; begin lTag := TFrmBase(FindAnyClass(aMyForm)); // with (lTag).Create(UniApplication) do begin .... Show(); end; end; procedure TMainForm.onClick(Sender : TObect); begin showMyForm('MyPersonalForm'); end; If it can serve, I attach the units Bye Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.