gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:46:43 25 4
gpt4 key购买 nike

我有一个记录类型

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, 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;

然后你的函数调用变成:

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

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

关于Delphi:将记录参数分解为字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45862805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com