Given a record type:
TItem = record
UPC : string[20];
Price : Currency;
Cost : Currency;
...
end;
And the name of a field as a string, how can I get the offset of that field within the record? I need to do this at runtime - the name of the field to access is decided at runtime.
Example:
var
pc : Integer;
fieldName : string;
value : Currency;
begin
pc := Integer(@item); // item is defined and filled elsewhere
fieldName := Text1.Text; // user might type 'Cost' or 'Price' etc
Inc(pc, GetItemFieldOffset(fieldName)); // how do I implement GetItemFieldOffset?
value := PCurrency(pc)^;
..
I'm using Delphi 7.
name : string
tovalue : currency
. – Coccidioidomycosis