Skip to content

Commit 12a2a5f

Browse files
author
pyscripter
committed
FPC compatibility
1 parent bcfddda commit 12a2a5f

21 files changed

+1654
-186
lines changed

PythonForDelphi/Components/Sources/Core/WrapDelphi.pas

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,24 +358,17 @@ TMyClass = class(TInterfacedObject, IFreeNotification)
358358
private
359359
fFreeNotifImpl : TFreeNotificationImpl;
360360
protected
361-
property FreeNotifImpl : TFreeNotificationImpl read fFreeNotifImpl implements IFreeNotification;
361+
property FreeNotifImpl : IFreeNotification read fFreeNotifImpl implements IFreeNotification;
362362
public
363363
constructor Create;
364-
destructor Destroy; override;
365364
end;
366365
367366
constructor TMyClass.Create;
368367
begin
369368
fFreeNotifImpl := TFreeNotificationImpl.Create(Self);
370369
end;
371-
372-
destructor TMyClass.Destroy;
373-
begin
374-
fFreeNotifImpl.Free;
375-
inherited;
376-
end;
377370
}
378-
TFreeNotificationImpl = class(TObject)
371+
TFreeNotificationImpl = class(TInterfacedObject, IFreeNotification)
379372
private
380373
fSubscribers : TInterfaceList;
381374
fOwner: TObject;
@@ -1054,7 +1047,11 @@ function SetToPython(ATypeInfo: PTypeInfo; AValue : Integer) : PPyObject; overlo
10541047

10551048
function SetToPython(APropInfo: PPropInfo; AValue : Integer) : PPyObject; overload;
10561049
begin
1050+
{$IFDEF FPC}
1051+
Result := SetToPython(GetTypeData(APropInfo.PropType)^.CompType, AValue);
1052+
{$ELSE FPC}
10571053
Result := SetToPython(GetTypeData(APropInfo^.PropType^)^.CompType^, AValue);
1054+
{$ENDIF FPC}
10581055
end;
10591056

10601057
function SetToPython(AInstance: TObject; APropInfo: PPropInfo) : PPyObject; overload;
@@ -1076,7 +1073,11 @@ function PythonToSet(ASet : PPyObject; APropInfo: PPropInfo) : Integer;
10761073
begin
10771074
Assert(PySequence_Check(ASet) <> 0, 'PythonToSet expects a Python sequence as first parameter');
10781075

1076+
{$IFDEF FPC}
1077+
EnumInfo := GetTypeData(APropInfo^.PropType)^.CompType;
1078+
{$ELSE FPC}
10791079
EnumInfo := GetTypeData(APropInfo^.PropType^)^.CompType^;
1080+
{$ENDIF FPC}
10801081
for i := 0 to PySequence_Length(ASet)-1 do
10811082
begin
10821083
EnumObj := PySequence_GetItem(ASet, i);
@@ -1136,6 +1137,7 @@ TPyDelphiMethodObject = class (TPyObject)
11361137

11371138
constructor TFreeNotificationImpl.Create(AOwner: TObject);
11381139
begin
1140+
inherited Create;
11391141
Assert(Assigned(AOwner));
11401142
fOwner := AOwner;
11411143
end;
@@ -1555,10 +1557,19 @@ function TPyDelphiObject.GetAttrO(key: PPyObject): PPyObject;
15551557
Result := SetToPython(Self.DelphiObject, PropInfo)
15561558
end else if PropInfo^.PropType^.Kind = tkEnumeration then begin
15571559
begin
1560+
{$IFDEF FPC}
1561+
if GetTypeData(PropInfo^.PropType)^.BaseType = TypeInfo(Boolean) then
1562+
{$ELSE FPC}
15581563
if GetTypeData(PropInfo^.PropType^)^.BaseType^ = TypeInfo(Boolean) then
1564+
{$ENDIF FPC}
15591565
Result := GetPythonEngine.VariantAsPyObject(Boolean(GetOrdProp(Self.DelphiObject, PropInfo)))
15601566
else
1561-
Result := GetPythonEngine.PyString_FromString(PAnsiChar(AnsiString(GetEnumName(PropInfo^.PropType^, GetOrdProp(Self.DelphiObject, PropInfo)))));
1567+
{$IFDEF FPC}
1568+
Result := GetPythonEngine.PyString_FromString(PAnsiChar(AnsiString(GetEnumName(PropInfo^.PropType,
1569+
{$ELSE FPC}
1570+
Result := GetPythonEngine.PyString_FromString(PAnsiChar(AnsiString(GetEnumName(PropInfo^.PropType^,
1571+
{$ENDIF FPC}
1572+
GetOrdProp(Self.DelphiObject, PropInfo)))));
15621573
end
15631574
end else
15641575
Result := GetPythonEngine.VariantAsPyObject(GetPropValue(DelphiObject, PropInfo));
@@ -1825,7 +1836,11 @@ function TPyDelphiObject.SetAttrO(key, value: PPyObject): Integer;
18251836
if PyObject is TPyDelphiObject then
18261837
begin
18271838
Obj := TPyDelphiObject(PyObject).DelphiObject;
1839+
{$IFDEF FPC}
1840+
if Obj.ClassType.InheritsFrom(GetTypeData(PropInfo^.PropType).ClassType) then
1841+
{$ELSE FPC}
18281842
if Obj.ClassType.InheritsFrom(GetTypeData(PropInfo^.PropType^).ClassType) then
1843+
{$ENDIF FPC}
18291844
begin
18301845
SetOrdProp(DelphiObject, PropInfo, NativeInt(Obj));
18311846
Result := 0;
@@ -1863,7 +1878,7 @@ function TPyDelphiObject.SetAttrO(key, value: PPyObject): Integer;
18631878
begin
18641879
try
18651880
V := GetPythonEngine.PyObjectAsVariant(Value);
1866-
if (PropInfo.PropType^^.Kind = tkEnumeration) and (VarType(V) = varOleStr) then
1881+
if (PropInfo.PropType^.Kind = tkEnumeration) and (VarType(V) = varOleStr) then
18671882
// Special case that occurs in Python3000
18681883
V := VarAsType(V, varString); //Downcast to string
18691884
SetPropValue(DelphiObject, PropInfo, V);
@@ -2485,7 +2500,11 @@ function TEventHandlers.Link(AComponent: TObject; APropInfo: PPropInfo;
24852500
begin
24862501
if SupportsFreeNotification(AComponent) then
24872502
begin
2503+
{$IFDEF FPC}
2504+
_handlerClass := FindHandler(APropInfo^.PropType);
2505+
{$ELSE FPC}
24882506
_handlerClass := FindHandler(APropInfo^.PropType^);
2507+
{$ENDIF FPC}
24892508
if Assigned(_handlerClass) then
24902509
begin
24912510
Unlink(AComponent, APropInfo);

PythonForDelphi/Components/Sources/Core/WrapDelphiComCtrls.pas

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TTabChangingEventHandler = class(TEventHandler)
1818
class function GetTypeInfo : PTypeInfo; override;
1919
end;
2020

21+
{$IFNDEF FPC}
2122
TPyDelphiDateTimePicker = class (TPyDelphiWinControl)
2223
private
2324
function GetDelphiObject: TDateTimePicker;
@@ -27,6 +28,7 @@ TPyDelphiDateTimePicker = class (TPyDelphiWinControl)
2728
// Properties
2829
property DelphiObject: TDateTimePicker read GetDelphiObject write SetDelphiObject;
2930
end;
31+
{$ENDIF FPC}
3032

3133
TPyDelphiTabSheet = class (TPyDelphiWinControl)
3234
private
@@ -69,19 +71,27 @@ TPyDelphiPageControl = class (TPyDelphiWinControl)
6971
procedure SetDelphiObject(const Value: TPageControl);
7072
protected
7173
// methods
74+
{$IFNDEF FPC}
7275
function IndexOfTabAt_Wrapper(args : PPyObject) : PPyObject; cdecl;
7376
function GetHitTestInfoAt_Wrapper(args : PPyObject) : PPyObject; cdecl;
77+
{$ENDIF FPC}
7478
function TabRect_Wrapper(args : PPyObject) : PPyObject; cdecl;
79+
{$IFNDEF FPC}
7580
function ScrollTabs_Wrapper(args : PPyObject) : PPyObject; cdecl;
81+
{$ENDIF FPC}
7682
function FindNextPage_Wrapper(args : PPyObject) : PPyObject; cdecl;
7783
function SelectNextPage_Wrapper(args : PPyObject) : PPyObject; cdecl;
7884
// Property Getters
7985
function Get_ActivePage( AContext : Pointer) : PPyObject; cdecl;
8086
function Get_ActivePageIndex( AContext : Pointer) : PPyObject; cdecl;
87+
{$IFNDEF FPC}
8188
function Get_Canvas( AContext : Pointer) : PPyObject; cdecl;
89+
{$ENDIF FPC}
8290
function Get_PageCount( AContext : Pointer) : PPyObject; cdecl;
8391
function Get_Pages( AContext : Pointer) : PPyObject; cdecl;
92+
{$IFNDEF FPC}
8493
function Get_RowCount( AContext : Pointer) : PPyObject; cdecl;
94+
{$ENDIF FPC}
8595
// Property Setters
8696
function Set_ActivePage( AValue : PPyObject; AContext : Pointer) : integer; cdecl;
8797
function Set_ActivePageIndex( AValue : PPyObject; AContext : Pointer) : integer; cdecl;
@@ -96,7 +106,7 @@ TPyDelphiPageControl = class (TPyDelphiWinControl)
96106
implementation
97107

98108
uses
99-
WrapDelphiTypes;
109+
WrapDelphiTypes, ExtCtrls;
100110

101111
{ Register the wrappers, the globals and the constants }
102112
type
@@ -122,13 +132,16 @@ function TComCtrlsRegistration.Name: String;
122132
procedure TComCtrlsRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper);
123133
begin
124134
inherited;
135+
{$IFNDEF FPC}
125136
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiDateTimePicker);
137+
{$ENDIF FPC}
126138
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPageControl);
127139
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTabSheet);
128140

129141
APyDelphiWrapper.EventHandlers.RegisterHandler(TTabChangingEventHandler);
130142
end;
131143

144+
{$IFNDEF FPC}
132145
{ TPyDelphiDateTimePicker }
133146

134147
class function TPyDelphiDateTimePicker.DelphiObjectClass: TClass;
@@ -145,6 +158,7 @@ procedure TPyDelphiDateTimePicker.SetDelphiObject(const Value: TDateTimePicker);
145158
begin
146159
inherited DelphiObject := Value;
147160
end;
161+
{$ENDIF FPC}
148162

149163
{ TPyDelphiPageControl }
150164

@@ -179,6 +193,7 @@ function TPyDelphiPageControl.GetDelphiObject: TPageControl;
179193
Result := TPageControl(inherited DelphiObject);
180194
end;
181195

196+
{$IFNDEF FPC}
182197
function TPyDelphiPageControl.GetHitTestInfoAt_Wrapper(
183198
args: PPyObject): PPyObject;
184199

@@ -232,6 +247,7 @@ function TPyDelphiPageControl.GetHitTestInfoAt_Wrapper(
232247
Result := nil;
233248
end;
234249
end;
250+
{$ENDIF FPC}
235251

236252
function TPyDelphiPageControl.Get_ActivePage(AContext: Pointer): PPyObject;
237253
begin
@@ -247,10 +263,12 @@ function TPyDelphiPageControl.Get_ActivePageIndex(
247263
end;
248264
end;
249265

266+
{$IFNDEF FPC}
250267
function TPyDelphiPageControl.Get_Canvas(AContext: Pointer): PPyObject;
251268
begin
252269
Result := Wrap(DelphiObject.Canvas);
253270
end;
271+
{$ENDIF FPC}
254272

255273
function TPyDelphiPageControl.Get_PageCount(AContext: Pointer): PPyObject;
256274
begin
@@ -270,6 +288,7 @@ function TPyDelphiPageControl.Get_Pages(AContext: Pointer): PPyObject;
270288
end;
271289
end;
272290

291+
{$IFNDEF FPC}
273292
function TPyDelphiPageControl.Get_RowCount(AContext: Pointer): PPyObject;
274293
begin
275294
with GetPythonEngine do begin
@@ -292,6 +311,7 @@ function TPyDelphiPageControl.IndexOfTabAt_Wrapper(
292311
Result := nil;
293312
end;
294313
end;
314+
{$ENDIF FPC}
295315

296316
class procedure TPyDelphiPageControl.RegisterGetSets(
297317
PythonType: TPythonType);
@@ -301,32 +321,40 @@ class procedure TPyDelphiPageControl.RegisterGetSets(
301321
'Specifies the page currently displayed by the page control.', nil);
302322
PythonType.AddGetSet('ActivePageIndex', @TPyDelphiPageControl.Get_ActivePageIndex, @TPyDelphiPageControl.Set_ActivePageIndex,
303323
'Specifies the page currently displayed by the page control.', nil);
324+
{$IFNDEF FPC}
304325
PythonType.AddGetSet('Canvas', @TPyDelphiPageControl.Get_Canvas, nil,
305326
'Gives access to the tab control’s canvas.', nil);
327+
{$ENDIF FPC}
306328
PythonType.AddGetSet('PageCount', @TPyDelphiPageControl.Get_PageCount, nil,
307329
'Indicates the number of pages in the TPageControl object.', nil);
308330
PythonType.AddGetSet('Pages', @TPyDelphiPageControl.Get_Pages, nil,
309331
'Lists all the pages in the TPageControl.', nil);
332+
{$IFNDEF FPC}
310333
PythonType.AddGetSet('RowCount', @TPyDelphiPageControl.Get_RowCount, nil,
311334
'', nil);
335+
{$ENDIF FPC}
312336
end;
313337

314338
class procedure TPyDelphiPageControl.RegisterMethods(
315339
PythonType: TPythonType);
316340
begin
317341
inherited;
342+
{$IFNDEF FPC}
318343
PythonType.AddMethod('IndexOfTabAt', @TPyDelphiPageControl.IndexOfTabAt_Wrapper,
319344
'TPageControl.IndexOfTabAt()'#10 +
320345
'Indicates the index of the tab at a specified point.');
321346
PythonType.AddMethod('GetHitTestInfoAt', @TPyDelphiPageControl.GetHitTestInfoAt_Wrapper,
322347
'TPageControl.GetHitTestInfoAt()'#10 +
323348
'Returns information about the location of a point relative to the client area of the tab control.');
349+
{$ENDIF FPC}
324350
PythonType.AddMethod('TabRect', @TPyDelphiPageControl.TabRect_Wrapper,
325351
'TPageControl.TabRect()'#10 +
326352
'Returns the bounding rectangle for a specified tab.');
353+
{$IFNDEF FPC}
327354
PythonType.AddMethod('ScrollTabs', @TPyDelphiPageControl.ScrollTabs_Wrapper,
328355
'TPageControl.ScrollTabs()'#10 +
329356
'Scrolls the tabs that are visible when the tab control is not multi-line.');
357+
{$ENDIF FPC}
330358
PythonType.AddMethod('FindNextPage', @TPyDelphiPageControl.FindNextPage_Wrapper,
331359
'TPageControl.FindNextPage()'#10 +
332360
'Returns the next page in the page control before or after a specified page.');
@@ -335,6 +363,7 @@ class procedure TPyDelphiPageControl.RegisterMethods(
335363
'Changes the ActivePage to the first visible page that is before or after the currently active page.');
336364
end;
337365

366+
{$IFNDEF FPC}
338367
function TPyDelphiPageControl.ScrollTabs_Wrapper(
339368
args: PPyObject): PPyObject;
340369
var
@@ -350,6 +379,7 @@ function TPyDelphiPageControl.ScrollTabs_Wrapper(
350379
Result := nil;
351380
end;
352381
end;
382+
{$ENDIF FPC}
353383

354384
function TPyDelphiPageControl.SelectNextPage_Wrapper(
355385
args: PPyObject): PPyObject;
@@ -605,5 +635,7 @@ class function TTabChangingEventHandler.GetTypeInfo: PTypeInfo;
605635

606636
initialization
607637
RegisteredUnits.Add( TComCtrlsRegistration.Create );
638+
{$IFNDEF FPC}
608639
Classes.RegisterClasses([TDateTimePicker]);
640+
{$ENDIF FPC}
609641
end.

0 commit comments

Comments
 (0)