Re: [fpc-pascal] Read Field names from VMT

2024-02-01 Thread Amir--- via fpc-pascal
I see... The trick was to define TMyClass! Thanks! On 2/1/24 02:19, Michael Van Canneyt via fpc-pascal wrote: On Wed, 31 Jan 2024, Amir--- via fpc-pascal wrote: Without more info (declaration of ChildTClass, declaration of the constructor of that class etc), it is not possible to

Re: [fpc-pascal] Read Field names from VMT

2024-02-01 Thread Michael Van Canneyt via fpc-pascal
On Wed, 31 Jan 2024, Amir--- via fpc-pascal wrote: Without more info (declaration of ChildTClass, declaration of the constructor of that class etc), it is not possible to comment. We need a complete compilable code sample to provide you with more insight. Please have a look at the

Re: [fpc-pascal] Read Field names from VMT

2024-01-31 Thread Amir--- via fpc-pascal
Without more info (declaration of ChildTClass, declaration of the constructor of that class etc), it is not possible to comment. We need a complete compilable code sample to provide you with more insight. Please have a look at the attachment. Best, Amir FieldAddress.lpr.gz Description:

Re: [fpc-pascal] Read Field names from VMT

2024-01-30 Thread Michael Van Canneyt via fpc-pascal
On Mon, 29 Jan 2024, Amir--- via fpc-pascal wrote: I am still struggling with this! for i := 0 to vft^.Count - 1 do begin    vfe := vft^.Field[i];    Name := vfe^.Name;    ChildTClass := vft^.ClassTab^.ClassRef[vfe^.TypeIndex - 1]^;    ChildObj := ChildTClass.Create;   

Re: [fpc-pascal] Read Field names from VMT

2024-01-29 Thread Amir--- via fpc-pascal
I am still struggling with this! for i := 0 to vft^.Count - 1 do begin    vfe := vft^.Field[i];    Name := vfe^.Name;    ChildTClass := vft^.ClassTab^.ClassRef[vfe^.TypeIndex - 1]^;    ChildObj := ChildTClass.Create;    TObject(Obj.FieldAddress(Name)^) := ChildObj; end;

Re: [fpc-pascal] Read Field names from VMT

2024-01-22 Thread Amir--- via fpc-pascal
On 1/22/24 23:05, Michael Van Canneyt via fpc-pascal wrote: On Mon, 22 Jan 2024, Amir--- via fpc-pascal wrote:   Params := TParams.Create;   WriteLn(Params.Int2.IntVal);   WriteLn(TInteger(Params.FieldAddress('Int2')).IntVal); The third line does not work (the zipped code is attached).

Re: [fpc-pascal] Read Field names from VMT

2024-01-22 Thread Michael Van Canneyt via fpc-pascal
On Mon, 22 Jan 2024, Amir--- via fpc-pascal wrote:   Params := TParams.Create;   WriteLn(Params.Int2.IntVal);   WriteLn(TInteger(Params.FieldAddress('Int2')).IntVal); The third line does not work (the zipped code is attached). It should be

Re: [fpc-pascal] Read Field names from VMT

2024-01-22 Thread Amir--- via fpc-pascal
  Params := TParams.Create;   WriteLn(Params.Int2.IntVal);   WriteLn(TInteger(Params.FieldAddress('Int2')).IntVal); The third line does not work (the zipped code is attached). On 1/21/24 23:43, Michael Van Canneyt via fpc-pascal wrote: On Sun, 21 Jan 2024, Amir--- via fpc-pascal wrote: How

Re: [fpc-pascal] Read Field names from VMT

2024-01-21 Thread Michael Van Canneyt via fpc-pascal
On Sun, 21 Jan 2024, Amir--- via fpc-pascal wrote: How can I set the value? I tried something like Test := TTest.Create Ptr := Pointer(Test); TSub(Ptr+8) := TSub.Create; But it is not working? Depending on your platform, it can be an alignment issue. Use function

Re: [fpc-pascal] Read Field names from VMT

2024-01-21 Thread Amir--- via fpc-pascal
How can I set the value? I tried something like Test := TTest.Create Ptr := Pointer(Test); TSub(Ptr+8) := TSub.Create; But it is not working? You can use the PVmtFieldTable and PVmtFieldEntry types from the TypInfo unit: === code begin === program tfield; {$mode objfpc}{$H+} uses  

Re: [fpc-pascal] Read Field names from VMT

2023-12-27 Thread Amir via fpc-pascal
Thank you!On Dec 27, 2023 7:46 AM, Sven Barth via fpc-pascal wrote: Am 26.12.2023 um 21:29 schrieb Amir--- via fpc-pascal: On 12/26/23 01:14, Sven Barth via fpc-pascal wrote:

Re: [fpc-pascal] Read Field names from VMT

2023-12-27 Thread Sven Barth via fpc-pascal
Am 26.12.2023 um 21:29 schrieb Amir--- via fpc-pascal: On 12/26/23 01:14, Sven Barth via fpc-pascal wrote: Amir--- via fpc-pascal schrieb am Di., 26. Dez. 2023, 07:03: Hi,    I want to retrieve the name of the fields in a record/class, at run time. It looks like

Re: [fpc-pascal] Read Field names from VMT

2023-12-26 Thread Amir--- via fpc-pascal
On 12/26/23 01:14, Sven Barth via fpc-pascal wrote: Amir--- via fpc-pascal schrieb am Di., 26. Dez. 2023, 07:03: Hi,    I want to retrieve the name of the fields in a record/class, at run time. It looks like "TVmt.vFieldTable" is what I need. But I cannot find any

Re: [fpc-pascal] Read Field names from VMT

2023-12-26 Thread Sven Barth via fpc-pascal
Amir--- via fpc-pascal schrieb am Di., 26. Dez. 2023, 07:03: > Hi, > >I want to retrieve the name of the fields in a record/class, at run > time. It looks like "TVmt.vFieldTable" is what I need. But I cannot find > any documentation about how to explore the content of this table. I >

[fpc-pascal] Read Field names from VMT

2023-12-25 Thread Amir--- via fpc-pascal
Hi,   I want to retrieve the name of the fields in a record/class, at run time. It looks like "TVmt.vFieldTable" is what I need. But I cannot find any documentation about how to explore the content of this table. I appreciate any pointer. Thank you, Amir