Last active
March 22, 2025 06:04
-
-
Save freeonterminate/fd7b737ca257f3dd363933f9835a3d7b to your computer and use it in GitHub Desktop.
Object Pascal も進化してるよ(プログラムの内容は全く意味が無いよ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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