Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Named-parameters/Delphi/named-parameters.delphi
Normal file
55
Task/Named-parameters/Delphi/named-parameters.delphi
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
program Named_parameters;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
System.SysUtils;
|
||||
|
||||
type
|
||||
TParams = record
|
||||
fx, fy, fz: Integer;
|
||||
function x(value: Integer): TParams;
|
||||
function y(value: Integer): TParams;
|
||||
function z(value: Integer): TParams;
|
||||
class function _: TParams; static;
|
||||
end;
|
||||
|
||||
function Sum(Param: TParams): Integer;
|
||||
begin
|
||||
Result := Param.fx + Param.fy + Param.fz;
|
||||
end;
|
||||
|
||||
{ TParams }
|
||||
|
||||
function TParams.x(value: Integer): TParams;
|
||||
begin
|
||||
Result := Self;
|
||||
Result.fx := value;
|
||||
end;
|
||||
|
||||
function TParams.y(value: Integer): TParams;
|
||||
begin
|
||||
Result := Self;
|
||||
Result.fy := value;
|
||||
end;
|
||||
|
||||
function TParams.z(value: Integer): TParams;
|
||||
begin
|
||||
Result := Self;
|
||||
Result.fz := value;
|
||||
end;
|
||||
|
||||
class function TParams._: TParams;
|
||||
begin
|
||||
Result.fx := 0; // default x
|
||||
Result.fy := 0; // default y
|
||||
Result.fz := 0; // default z
|
||||
end;
|
||||
|
||||
begin
|
||||
writeln(sum(TParams._.x(2).y(3).z(4))); // 9
|
||||
|
||||
writeln(sum(TParams._.z(4).x(3).y(5))); // 12
|
||||
|
||||
{$IFNDEF UNIX} readln; {$ENDIF}
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue