3

I have to use records in Lazarus (due to TVirtualStringTree).

If I have a simple record:

type
  myrec = record
    name: string;
  end;

Is there a way how to access the field by reference? i.e. to make a function:

getField('name', searchRecord);

or is there a way how to iterate over fieldnames?

manlio
  • 18,345
  • 14
  • 76
  • 126
hugo
  • 76
  • 6
  • So, are you looking for a way to write a function that will return a record that matches the `name` field value after searching in a virtual tree view ? – TLama May 29 '14 at 09:10
  • i want to access any field of record - so the function should return a field, which i pass as parametr to that function. in real the record will keep huge amount of data (tenth of fields) - i need to not to type them manually each time. the best would be if there is a way how list fieldnames, or iterate fields and read each name of particular field. – hugo May 29 '14 at 09:19
  • Ah, I see. You're looking for a RTTI way to access record field value by name. I'm not sure about it, but I think that FPC doesn't support so deep RTTI, but let's hope that I'm wrong... – TLama May 29 '14 at 09:27
  • exactly! thanks for clearing my question i did not know about RTTI – hugo May 29 '14 at 09:35
  • 3
    In FPC/trunk work has done on extending RTTI, but they chose to extend unit typinfo, rather than build a new unit hierarchy. Note that for all forms of extended RTTI selectively enabling it where needed is paramount, since it blows up binaries gigantically (and symbols being reachable by RTTI may inhibit certain optimizations). In general, the need for it in purposes unrelated to streaming is generally a indicator for bad design IMHO. – Marco van de Voort May 29 '14 at 11:41

1 Answers1

0

i guest you can use JSON theres fpjson unit on lazarus

http://freepascal.org/docs-html/fcl/fpjson/index.html