Hello,
should RTTI work on Delphi 7 (running on Win XP)?
Code:
unit functions;
interface
{$APPTYPE CONSOLE}
{$R *.res}
uses
SysUtils, RTTI, TypInfo;
type
TSampleRecord = record
SomeInt: Integer;
SomeStr: String;
SomeFloat: Single;
end;
implementation
function GetField(Rec: TValue; const FieldName: String): String;
var
Context: TRTTIContext;
RTTIRecord: TRTTIRecordType;
RecField: TRTTIField;
RecValue: TValue;
begin
if (Rec.Kind = tkRecord) then
begin
RTTIRecord := Context.GetType(Rec.TypeInfo).AsRecord;
RecField := RTTIRecord.GetField(FieldName);
RecValue := RecField.GetValue(Rec.GetReferenceToRawData);
Result := RecValue.ToString();
if (RecValue.Kind = tkFloat) then
Result := Format('%.4f', [RecValue.AsExtended]);
end;
end;
end.
Taken from here and modify (I need to include it into program to access record member dynamically).
Error:
[Fatal Error] functions.pas(10): File not found: 'RTTI.dcu'
What am I doing wrong?
Bookmarks