Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Recursive generic record fields show


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 28, 2015 10:04 AM Last Post By: Leif Uneus
Stefano Gamberoni

Posts: 5
Registered: 4/22/13
Recursive generic record fields show  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2015 3:21 AM
Hi,
I'm trying to create a recursive function that shows the list of fields in a record generic.
for example:

my_rec2=record
a:integer;
b:integer:
end;

my_rec=record
a:String;
b:boolean;
c: integer;
d:my_rec2;
end;

I would like something like that(use simple real data):
my_rec
a=helo
b=true
c=100
my_rec2
a=1
b=2

I use rtti to find the fileds name but i cannot pass a generic record type (in this example my_rec, my_rec2)
So I thought about using a pointer but it does't work;

procedure listOfFields(mypointer_struncture:pointer;mypointer_data:pointer);
var
[..]
begin
[..]
rtype := TRTTIContext.Create.GetType(mypointer);
[..]
if ((AnsiCompareStr(fields[i].GetValue(mypointer_data).ToString,'(record)')=0)) then
listOfFields(??,??);

Or is there a function to convert string in a record name?
Any ideas?
Thanks

Stefano
George Wei

Posts: 40
Registered: 9/18/05
Re: Recursive generic record fields show  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2015 5:50 AM   in response to: Stefano Gamberoni in response to: Stefano Gamberoni
Neither my_rec2 nor my_rec are generic types. The parameters of procedure listOfFields should be declared exactly.

George

Stefano Gamberoni wrote:
Hi,
I'm trying to create a recursive function that shows the list of fields in a record generic.
for example:

my_rec2=record
a:integer;
b:integer:
end;

my_rec=record
a:String;
b:boolean;
c: integer;
d:my_rec2;
end;

I would like something like that(use simple real data):
my_rec
a=helo
b=true
c=100
my_rec2
a=1
b=2

I use rtti to find the fileds name but i cannot pass a generic record type (in this example my_rec, my_rec2)
So I thought about using a pointer but it does't work;

procedure listOfFields(mypointer_struncture:pointer;mypointer_data:pointer);
var
[..]
begin
[..]
rtype := TRTTIContext.Create.GetType(mypointer);
[..]
if ((AnsiCompareStr(fields[i].GetValue(mypointer_data).ToString,'(record)')=0)) then
listOfFields(??,??);

Or is there a function to convert string in a record name?
Any ideas?
Thanks

Stefano

Edited by: George Wei on Feb 27, 2015 5:56 AM
Leif Uneus

Posts: 33
Registered: 8/12/98
Re: Recursive generic record fields show  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2015 10:04 AM   in response to: Stefano Gamberoni in response to: Stefano Gamberoni
Stefano Gamberoni wrote:
Hi,
I'm trying to create a recursive function that shows the list of fields in a record generic.


Or is there a function to convert string in a record name?
Any ideas?
Thanks

If you study my answer at SO,

http://stackoverflow.com/a/11514088/576719

you can unwind most types (including records) with RTTI.

Have fun !

/Leif

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02