我的问题很简单。我有一个具有以下代码的 dwsUnit:
type
TPointCoord = record
X: Float;
Y: Float;
Z: Float;
end;
type
TMyClass = class
private
fPosition: TPointCoord;
function GetPosition: TPointCoord;
procedure SetPosition(Val: TPointCoord);
public
property Position: TPointCoord read GetPosition write SetPosition;
constructor Create;
end;
function TMyClass.GetPosition: TPointCoord;
begin
Result := fPosition;
end;
procedure TMyClass.SetPosition(Val: TPointCoord);
begin
fPosition := Val;
end;
constructor TMyClass.Create;
begin
inherited Create;
fPosition.X := 1;
fPosition.Y := 2;
fPosition.Z := 3;
end;
var
mc: TMyClass;
begin
mc := TMyClass.Create;
mc.Position.X := 2; //Syntax Error
end.
在 mc.Position.X(或 Position.Y 或 Z)我得到:
Syntax Error: Cannot assign a value to the left-side argument [line: 42, column: 17]
这是什么意思?如果是属性,记录是只读的吗?以及我如何从 Delphi Side 访问它。(第二个问题,没什么大不了的)