메소드가 레코드구조체를 반환하는 경우 left assignment는 안됩니다. 델파이 문법이에요.
루도라 님이 쓰신 글 :
: 아래와 같은 코드를 컴파일 하면 에러가 나네요.
:
: type
: PR= ^TR;
: TR= record
: Form: TForm;
:
: class operator Implicit(const Value: TR): string;
: class operator Implicit(const Value: string): TR;
: class operator LeftShift(const Value1: TR; const Value2: string): TR;
: end
:
: ...
:
: class operator TR.Implicit(const Value: TR): string;
: begin
: Result:= Value.Form.Caption;
: end;
:
: class operator TR.Implicit(const Value: string): TR;
: begin
: Result.Form.Caption:= Value;
: end;
:
: class operator TR.LeftShift(const Value1: TR; const Value2: string): TR;
: begin
: Value1.Form.Caption:= Value2;
: Result:= Value1;
: end;
:
: function TForm1.GetR: TR;
: begin
: Result.Form:= Self;
: end;
:
: function TForm1.GetRP: PR;
: var
: R: TR;
: begin
: R.Form:= Self;
: Result:= @R;
: end;
:
: procedure TForm1.Test1;
: begin
: GetR:= 'Hello, World'; // <-- E2064 Left side cannot be assigned to
: GetRP^:= 'Hello, World'; // 잘됩니다.
: GetR shl 'Hello, World'; // 잘됩니다.
: end;
:
: assign 연산자에서만 에러가 나는데 버그일까요? 아니면 제가 뭔가 잘못한 걸까요?
:
: 연산자 오버로딩 자체는 잘 됩니다.
:
: var
: R: TR;
: begin
: R.Form:= Self;
: R:= 'Hello, World'; // 잘됩니다.
: end;
:
: ps. 쓸데없이 긴 코드를 늘어놔서 죄송합니다. ㅠ.ㅠ
:
|