Skip to content

Commit 2a4e093

Browse files
committed
Fix Delphi compatibility
1 parent 0a38566 commit 2a4e093

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

code-samples/generics_lists.dpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type
88
Name: string;
99
end;
1010

11-
TAppleList = specialize TObjectList<TApple>;
11+
TAppleList = {$ifdef FPC_OBJFPC}specialize{$endif} TObjectList<TApple>;
1212

1313
var
1414
A: TApple;

code-samples/generics_sorting.dpr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type
1818
Name: string;
1919
end;
2020

21-
TAppleList = specialize TObjectList<TApple>;
21+
TAppleList = {$ifdef FPC_OBJFPC}specialize{$endif} TObjectList<TApple>;
2222

2323
function CompareApples(
2424
{$ifdef GENERICS_CONSTREF}constref{$else}const{$endif}
@@ -28,7 +28,7 @@ begin
2828
end;
2929

3030
type
31-
TAppleComparer = specialize TComparer<TApple>;
31+
TAppleComparer = {$ifdef FPC_OBJFPC}specialize{$endif} TComparer<TApple>;
3232
var
3333
A: TApple;
3434
L: TAppleList;
@@ -47,7 +47,7 @@ begin
4747
A.Name := '22';
4848
L.Add(A);
4949

50-
L.Sort(TAppleComparer.Construct(@CompareApples));
50+
L.Sort(TAppleComparer.Construct({$ifdef FPC_OBJFPC}@{$endif} CompareApples));
5151

5252
Writeln('Count: ', L.Count);
5353
Writeln(L[0].Name);

code-samples/interfaces_com_test.dpr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ var
5353

5454
procedure UseInterfaces;
5555
begin
56-
if C1 is IMyInterface then
57-
//if Supports(C1, IMyInterface) then // equivalent to "is" check above
56+
// In FPC, you could also check using "is", like:
57+
//if C1 is IMyInterface then ...
58+
59+
if Supports(C1, IMyInterface) then
5860
UseThroughInterface(C1 as IMyInterface);
59-
if C2 is IMyInterface then
61+
if Supports(C2, IMyInterface) then
6062
UseThroughInterface(C2 as IMyInterface);
61-
if C3 is IMyInterface then
63+
if Supports(C3, IMyInterface) then
6264
UseThroughInterface(C3 as IMyInterface);
6365
end;
6466

0 commit comments

Comments
 (0)