Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-02

Class helper properties

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

http://wiki.freepascal.org/Helper_types#Usage says class helpers can use properties. Why am I getting this error?

program test;
type
	TMyObject = class
		m_num: integer;
		property num1: integer read m_num;
	end;
	THelper = class helper for TMyObject
		property num2: integer read m_num;	// ERROR: Unknown class field or method identifier "m_num"
	end;
begin
end.

Regards,
Ryan Joseph

Reply by email

Anthony Walter
to Ryan Joseph

Ryan, I am guessing in the declaration you need to read or write from methods on the helper only and not from fields or methods on the type you are extending.

type
  TMyObject = class
  private
    FNum: Integer;
  public
    property Num1: Integer read FNum;
  end;
  TMyObjectHelper = class helper for TMyObject
  private
    function GetNum2: Integer;
  public
    property Num2: Integer read GetNum2;
  end;
implementation
function TMyObjectHelper,GetNum2: Integer;
begin
  Result := FNum;
end;

Reply by email

Mattias Gaertner
to Ryan Joseph: http://wiki.freepascal.org/Helper_types#Usage says class helpers can use properties. Why…
Show quoted text 13 lines
http://wiki.freepascal.org/Helper_types#Usage says class helpers can use properties. Why am I getting this error? program test; type TMyObject = class m_num: integer; property num1: integer read m_num; end; THelper = class helper for TMyObject property num2: integer read m_num; // ERROR: Unknown class field or method identifier "m_num" end;

This is Delphi compatible.
A helper property can only access helper methods.
A property of a class can access helper methods.

pas2js allows both directions.

Mattias

Reply by email