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

前端之家收集整理的这篇文章主要介绍了Delphi:将记录参数分解为字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个记录类型
tLine = record
  X,Y,Count : integer;
  V : boolean;
end;

我有一个

function fRotate(zLine: tLine; zAngle: double): tLine;

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

NewLine:=fRotate((zLine.X,zLine.Y-1,zLine.Count,zLine.V),zAngle);

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

dec(zLine.Y);
NewLine:=fRotate(zLine,zAngle);
inc(zLine.Y);

TIA

解决方法

你通常会为此做一个功能.在具有增强记录的现代Delphi中,我喜欢使用这样的静态类函数
type
  TLine = record
  public
    X: Integer;
    Y: Integer;
    Count: Integer;
    V: Boolean;
  public
    class function New(X,Count: Integer; V: Boolean): TLine; static;
  end;

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

然后你的函数调用变为:

NewLine := fRotate(TLine.New(zLine.X,zAngle);

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

原文链接:https://www.f2er.com/delphi/102382.html

猜你在找的Delphi相关文章