Skip to content

Commit 5b2293f

Browse files
committed
Adjust many ifdefs to account also for Delphi
1 parent 45c9b97 commit 5b2293f

File tree

119 files changed

+673
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+673
-449
lines changed
Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
{ Working example adjusted from
2-
https://forum.lazarus.freepascal.org/index.php?topic=59468.0 }
3-
4-
{$ifdef FPC}
5-
{$mode objfpc}{$H+}{$J-}
6-
{$modeswitch functionreferences}
7-
{$modeswitch anonymousfunctions}
8-
{$endif}
9-
10-
uses Classes;
11-
12-
type
13-
TFunc = function: LongInt;
14-
15-
var
16-
p: TProcedure;
17-
f: TFunc;
18-
n: TNotifyEvent;
19-
begin
20-
procedure(const aArg: String)
21-
begin
22-
Writeln(aArg);
23-
end('Hello World');
24-
25-
p := procedure
26-
begin
27-
Writeln('Foobar');
28-
end;
29-
p();
30-
31-
n := procedure(aSender: TObject)
32-
begin
33-
Writeln(HexStr(Pointer(aSender)));
34-
end;
35-
n(Nil);
36-
37-
f := function MyRes : LongInt
38-
begin
39-
MyRes := 42;
40-
end;
41-
Writeln(f());
1+
{ Working example adjusted from
2+
https://forum.lazarus.freepascal.org/index.php?topic=59468.0 }
3+
4+
{$ifdef FPC}
5+
{$mode objfpc}{$H+}{$J-}
6+
{$modeswitch functionreferences}
7+
{$modeswitch anonymousfunctions}
8+
{$endif}
9+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
10+
11+
uses Classes;
12+
13+
type
14+
TFunc = function: LongInt;
15+
16+
var
17+
p: TProcedure;
18+
f: TFunc;
19+
n: TNotifyEvent;
20+
begin
21+
procedure(const aArg: String)
22+
begin
23+
Writeln(aArg);
24+
end('Hello World');
25+
26+
p := procedure
27+
begin
28+
Writeln('Foobar');
29+
end;
30+
p();
31+
32+
n := procedure(aSender: TObject)
33+
begin
34+
Writeln(HexStr(Pointer(aSender)));
35+
end;
36+
n(Nil);
37+
38+
f := function MyRes : LongInt
39+
begin
40+
MyRes := 42;
41+
end;
42+
Writeln(f());
4243
end.

code-samples/anon_functions_list_map_foreach.dpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{$modeswitch functionreferences}
66
{$modeswitch anonymousfunctions}
77
{$endif}
8-
{$apptype CONSOLE}
8+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
99

1010
uses SysUtils, Generics.Collections;
1111

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
{ Anonymous functions test. }
2-
3-
{$ifdef FPC}
4-
{$mode objfpc}{$H+}{$J-}
5-
{$modeswitch functionreferences}
6-
{$modeswitch anonymousfunctions}
7-
{$endif}
8-
{$apptype CONSOLE}
9-
10-
type
11-
TMyFunction = reference to function (const A, B: Integer): Integer;
12-
13-
function ProcessTheList(const F: TMyFunction): Integer;
14-
var
15-
I: Integer;
16-
begin
17-
Result := 1;
18-
for I := 2 to 10 do
19-
Result := F(Result, I);
20-
end;
21-
22-
var
23-
SomeFunction: TMyFunction;
24-
begin
25-
// Assign anonymous function to a variable
26-
SomeFunction :=
27-
function(const A, B: Integer): Integer
28-
begin
29-
Result := A + B;
30-
end;
31-
WriteLn('1 + 2 + 3 ... + 10 = ', ProcessTheList(SomeFunction));
32-
33-
// Or, simpler, just define the anonymous function inside the parameter
34-
WriteLn('1 + 2 + 3 ... + 10 = ', ProcessTheList(
35-
function(const A, B: Integer): Integer
36-
begin
37-
Result := A + B;
38-
end
39-
));
40-
41-
// Similar test, now with multiplication
42-
WriteLn('1 * 2 * 3 ... * 10 = ', ProcessTheList(
43-
function(const A, B: Integer): Integer
44-
begin
45-
Result := A * B;
46-
end
47-
));
48-
end.
1+
{ Anonymous functions test. }
2+
3+
{$ifdef FPC}
4+
{$mode objfpc}{$H+}{$J-}
5+
{$modeswitch functionreferences}
6+
{$modeswitch anonymousfunctions}
7+
{$endif}
8+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
9+
10+
type
11+
TMyFunction = reference to function (const A, B: Integer): Integer;
12+
13+
function ProcessTheList(const F: TMyFunction): Integer;
14+
var
15+
I: Integer;
16+
begin
17+
Result := 1;
18+
for I := 2 to 10 do
19+
Result := F(Result, I);
20+
end;
21+
22+
var
23+
SomeFunction: TMyFunction;
24+
begin
25+
// Assign anonymous function to a variable
26+
SomeFunction :=
27+
function(const A, B: Integer): Integer
28+
begin
29+
Result := A + B;
30+
end;
31+
WriteLn('1 + 2 + 3 ... + 10 = ', ProcessTheList(SomeFunction));
32+
33+
// Or, simpler, just define the anonymous function inside the parameter
34+
WriteLn('1 + 2 + 3 ... + 10 = ', ProcessTheList(
35+
function(const A, B: Integer): Integer
36+
begin
37+
Result := A + B;
38+
end
39+
));
40+
41+
// Similar test, now with multiplication
42+
WriteLn('1 * 2 * 3 ... * 10 = ', ProcessTheList(
43+
function(const A, B: Integer): Integer
44+
begin
45+
Result := A * B;
46+
end
47+
));
48+
end.

code-samples/anotherunit.pas

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
{$mode objfpc}{$H+}{$J-}
2-
unit AnotherUnit;
3-
interface
4-
5-
uses
6-
Classes;
7-
8-
{ The "TComponent" type (class) is defined in the Classes unit.
9-
That's why we had to use the Classes unit above. }
10-
procedure DoSomethingWithComponent(var C: TComponent);
11-
12-
implementation
13-
14-
uses SysUtils;
15-
16-
procedure DoSomethingWithComponent(var C: TComponent);
17-
begin
18-
{ The FreeAndNil procedure is defined in the SysUtils unit.
19-
Since we only refer to its name in the implementation,
20-
it was OK to use the SysUtils unit in the "implementation" section. }
21-
FreeAndNil(C);
22-
end;
23-
24-
end.
1+
unit AnotherUnit;
2+
3+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
4+
5+
interface
6+
7+
uses
8+
Classes;
9+
10+
{ The "TComponent" type (class) is defined in the Classes unit.
11+
That's why we had to use the Classes unit above. }
12+
procedure DoSomethingWithComponent(var C: TComponent);
13+
14+
implementation
15+
16+
uses SysUtils;
17+
18+
procedure DoSomethingWithComponent(var C: TComponent);
19+
begin
20+
{ The FreeAndNil procedure is defined in the SysUtils unit.
21+
Since we only refer to its name in the implementation,
22+
it was OK to use the SysUtils unit in the "implementation" section. }
23+
FreeAndNil(C);
24+
end;
25+
26+
end.

code-samples/array_of_const.dpr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
23

34
uses SysUtils;
45

code-samples/callbacks.dpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{$mode objfpc}{$H+}{$J-}
1+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
23

34
function Add(const A, B: Integer): Integer;
45
begin

code-samples/callbacks_of_object.dpr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{$mode objfpc}{$H+}{$J-}
1+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
3+
24
uses
35
SysUtils;
46

code-samples/class_properties.dpr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{$mode objfpc}{$H+}{$J-}
1+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
3+
24
type
35
TMyClass = class
46
strict private

code-samples/exception_finally.dpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{$mode objfpc}{$H+}{$J-}
1+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
23

34
program MyProgram;
45

code-samples/exception_in_constructor_test.dpr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
{$mode objfpc}{$H+}{$J-}
1+
{$ifdef FPC} {$mode objfpc}{$H+}{$J-} {$endif}
2+
{$ifdef MSWINDOWS} {$apptype CONSOLE} {$endif}
3+
24
uses
35
SysUtils;
46

0 commit comments

Comments
 (0)