55interface
66
77uses
8- System.Classes, FMX.Forms,
8+ System.Classes, System.SysUtils, FMX.Forms,
99 PythonEngine, WrapFmxTypes, WrapDelphiClasses, WrapFmxControls;
1010
1111type
@@ -88,6 +88,8 @@ TPyDelphiScreen = class(TPyDelphiComponent)
8888 property DelphiObject: TScreen read GetDelphiObject write SetDelphiObject;
8989 end ;
9090
91+ EInvalidFormClass = class (Exception);
92+
9193implementation
9294
9395uses
@@ -165,6 +167,11 @@ TCommonCustomFormClass = class of TCommonCustomForm;
165167 LFormClass: TCommonCustomFormClass;
166168 LClassName: string;
167169begin
170+ LFormClass := nil ;
171+ // get de default form class
172+ if DelphiObjectClass.InheritsFrom(TCommonCustomForm) then
173+ LFormClass := TCommonCustomFormClass(DelphiObjectClass);
174+
168175 // if we have a subclass of our Form wrapper, then check if we can find a
169176 // Delphi class that would have the same name as the Python class.
170177 // This would allow Python to instanciate an existing Delphi form class,
@@ -176,12 +183,12 @@ TCommonCustomFormClass = class of TCommonCustomForm;
176183 LClass := GetClass(' T' + LClassName);
177184 if Assigned(LClass) and LClass.InheritsFrom(TCommonCustomForm) then
178185 LFormClass := TCommonCustomFormClass(LClass);
179- end else begin
180- // get de default form class
181- if DelphiObjectClass.InheritsFrom(TCommonCustomForm) then
182- LFormClass := TCommonCustomFormClass(DelphiObjectClass);
183186 end ;
184187
188+ if not Assigned(LFormClass) then
189+ raise EInvalidFormClass.CreateFmt(' Type %s is not a valid form class' , [
190+ DelphiObjectClass.ClassName]);
191+
185192 // if it's not a design form, so we create it as a non-resourced form,
186193 // using the non-resourced constructor.
187194 // if the Owner is TApplication, then we have to call its CreateForm method,
0 commit comments