Delphi:将记录参数分解为字段

JRB*_*eau 8 delphi records parameter-passing

我有一个记录类型

tLine = record
  X, Y, Count : integer;
  V : boolean;
end;
Run Code Online (Sandbox Code Playgroud)

我有一个

function fRotate(zLine: tLine; zAngle: double): tLine;
Run Code Online (Sandbox Code Playgroud)

我想传递zLine,但是它的Y字段减少1.是否有办法将记录分解为过程或函数中的特定字段?我试过了

NewLine:=fRotate((zLine.X, zLine.Y-1, zLine.Count, zLine.V), zAngle);
Run Code Online (Sandbox Code Playgroud)

这不起作用.或者我必须做如下:

dec(zLine.Y);
NewLine:=fRotate(zLine, zAngle);
inc(zLine.Y);
Run Code Online (Sandbox Code Playgroud)

TIA

Dav*_*nan 9

你通常会为此做一个功能.在具有增强记录的现代Delphi中,我喜欢使用这样的静态类函数:

type
  TLine = record
  public
    X: Integer;
    Y: Integer;
    Count: Integer;
    V: Boolean;
  public
    class function New(X, Y, Count: Integer; V: Boolean): TLine; static;
  end;

class function TLine.New(X, Y, Count: Integer; V: Boolean): TLine;
begin
  Result.X := X;
  Result.Y := Y;
  Result.Count := Count;
  Result.V := V;
end;
Run Code Online (Sandbox Code Playgroud)

然后你的函数调用变为:

NewLine := fRotate(TLine.New(zLine.X, zLine.Y-1, zLine.Count, zLine.V), zAngle);
Run Code Online (Sandbox Code Playgroud)

在旧版本的Delphi中,您必须在全局范围内使用函数.