I’ve created new form instances like this:
var
ClassToUse: TFormClass;
begin
ClassToUse := TfrmMyForm; //CREATED AT DESIGN TIME
.
.
NewForm := ClassTouse.Create(NewTab); //NewTab is an instance of a tab
.
end;
The ABOVE code works fine.
But now I want to send a form as a string to a procedure that would create that form. Thus I changed the code to the following:
I’ve created new form instances like this:
var
ClassToUse: TFormClass;
begin
ClassToUse := GetClass(pFormName); //pFormName is a string -- ERROR IS HERE!!
.
.
NewForm := ClassTouse.Create(NewTab);
.
end;
This gives the following error:
Error: Incompatible types: got "TPersistentClass" expected "TFormClass"
Perhaps I’m on the wrong page… What is the right way of implementing this?
Thanks!
The
GetClassfunction returnsTPersistentClass. You cannot assign one of those to aTFormClass. For exactly the same reason why you cannot assign aTPersistentreference to aTFormreference.You can change the code to be like so: