Delphi:将记录参数分解为字段
发布时间:2020-12-15 04:01:15 所属栏目:大数据 来源:网络整理
导读:我有一个记录类型 tLine = record X,Y,Count : integer; V : boolean;end; 我有一个 function fRotate(zLine: tLine; zAngle: double): tLine; 我想传递zLine,但Y字段减少1.有没有办法将记录分解为过程或函数中的特定字段?我试过了 NewLine:=fRotate((zLine
我有一个记录类型
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中,您必须在全局范围内使用函数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |