Skip to content

Instantly share code, notes, and snippets.

@freeonterminate
Last active September 17, 2020 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freeonterminate/fd7b737ca257f3dd363933f9835a3d7b to your computer and use it in GitHub Desktop.
Save freeonterminate/fd7b737ca257f3dd363933f9835a3d7b to your computer and use it in GitHub Desktop.
Object Pascal も進化してるよ(プログラムの内容は全く意味が無いよ)
program プログラム;
uses
System.SysUtils
{$IFDEF ANDROID}
, Androidapi.JniBridge
{$ELSEIF IOS}
, iOSapi.Foundation
{$ENDIF}
;
type
TSample = class sealed
public type
TSampleFunc = reference to function(const Arg: Int32): TArray<String>;
private type
TInnerClass = class
private const
HELLO_MSG = 'Hello, Object Pascal !';
private
function GetHelloMsg: String; inline;
public
destructor Destroy; override; final;
property HelloMsg: String read GetHelloMsg;
end;
strict private class var
[Weak] FInnerClass: TInnerClass;
end;
TSampleHelper = class helper for TSample
public
class procedure Print(const Func: TSample.TSampleFunc);
end;
class procedure TSampleHelper.Print(const Func: TSample.TSampleFunc);
begin
var SB := TStringBuilder.Create;
try
var Inner := TInnerClass.Create;
try
for var S in Func(3) do
begin
SB.Append(S);
SB.Append(' ');
SB.Append(Inner.HelloMsg);
SB.AppendLine;
end;
finally
Inner.DisposeOf;
end;
Writeln(SB.ToString);
finally
SB.DisposeOf;
end;
end;
destructor TSample.TInnerClass.Destroy;
begin
Writeln('Destroy TInnerClass !');
inherited;
end;
function TSample.TInnerClass.GetHelloMsg: String;
begin
Result := HELLO_MSG;
end;
begin
TSample.Print(
function (const Arg: Int32): TArray<String>
var
i: Integer;
begin
SetLength(Result, Arg);
for i := 0 to High(Result) do
Result[i] := i.ToString;
end
);
Readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment