2010-12-30

E2197: Constant object cannot be passed as var parameter

常數物件不能傳入 var 參數!

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    FJson: String;
    procedure Set_Json(const Value: String);
    { Private declarations }
  public
    property Json: String read FJson write Set_Json;
    { Public declarations }
  end;

  procedure JsonSet(var aJson, aName, aValue: String);

procedure JsonSet(var aJson, aName, aValue: String);
begin
  // Set Value by Name in to aJSON
end;

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  JsonSet(Json, 'Name', 'Value');
end;

錯誤在 Line 10 的 Json, 位置。

修正 Property

public
    property Json: ISuperObject read Get_Json write Set_Json;
    { Public declarations }
  end;


增加 Method Overload

procedure JsonSet(var aJson, aName, aValue: String); overload;
  procedure JsonSet(oJson:ISuperObject; aName, aValue: String); overload;
[DCC Error]

沒有留言: