Sign in Join

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

Mailing lists / fpc-pascal / 2015-02

FieldAddress

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Torsten Bonde Christiansen

Hi,

What does it take for a class to access a field using FieldAddress(...)?

I have tried with both typeinfo on/off ({M+}), placing the field in private/protected/public/published
sections but to no avail.

My simple code is:

TMyObject = class
private
   FRef: TMyObject;
   procedure SetRef(AValue: TMyObject);
public
   property Ref: TMyObject read FRef write SetRef;
end;

then i have tried to get the adress in two ways:

AMyObject.FieldAddress('FRef');   //returns nil
AMyObject.FieldAddress('Ref'); //also returns nil

If i run my code through debugger, the VMT FieldTable is empty suggesting no information is
created. This happens in all cases of typeinfo on/off and differenc sections...

What can i do to make the fieldadress accessible?

Regards,
Torsten.

Reply by email

silvioprog
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 34 lines
Hi, What does it take for a class to access a field using FieldAddress(...)? I have tried with both typeinfo on/off ({M+}), placing the field in private/protected/public/published sections but to no avail. My simple code is: TMyObject = class private FRef: TMyObject; procedure SetRef(AValue: TMyObject); public property Ref: TMyObject read FRef write SetRef; end; then i have tried to get the adress in two ways: AMyObject.FieldAddress('FRef'); //returns nil AMyObject.FieldAddress('Ref'); //also returns nil If i run my code through debugger, the VMT FieldTable is empty suggesting no information is created. This happens in all cases of typeinfo on/off and differenc sections... What can i do to make the fieldadress accessible? Regards, Torsten.

This method return a field address, eg:

{$M+}
  TMyObject = class(TObject)
    FRef: TMyObject;
  end;

...

var
  VMyObject: TMyObject;
  VRef: Pointer;
begin
  VMyObject := TMyObject.Create;
  VRef := VMyObject.FieldAddress('FRef');

If you whant to get a property, use the TypInfo.GetObjectProp function.

Silvio Clécio My public projects - github.com/silvioprog

Reply by email

Torsten Bonde Christiansen
to silvioprog
silvioprog wrote 56 lines
On Tue, Feb 3, 2015 at 6:17 AM, Torsten Bonde Christiansen < > wrote: Hi, What does it take for a class to access a field using FieldAddress(...)? I have tried with both typeinfo on/off ({M+}), placing the field in private/protected/public/published sections but to no avail. My simple code is: TMyObject = class private FRef: TMyObject; procedure SetRef(AValue: TMyObject); public property Ref: TMyObject read FRef write SetRef; end; then i have tried to get the adress in two ways: AMyObject.FieldAddress('FRef'); //returns nil AMyObject.FieldAddress('Ref'); //also returns nil If i run my code through debugger, the VMT FieldTable is empty suggesting no information is created. This happens in all cases of typeinfo on/off and differenc sections... What can i do to make the fieldadress accessible? Regards, Torsten. This method return a field address, eg: {$M+} TMyObject = class(TObject) FRef: TMyObject; end; ... var VMyObject: TMyObject; VRef: Pointer; begin VMyObject := TMyObject.Create; VRef := VMyObject.FieldAddress('FRef'); If you whant to get a property, use the TypInfo.GetObjectProp function.

So FieldAddress can only access published fields?

Regards,
Torsten.

Reply by email