type
myrec = record
id:dWord;
name:array[0..31] of WideChar;
three:dword;
count:dword;
ShuXing:Single;
ShuXing2:dword;
ShuXing3:dWORD;
end;
var
Form1: TForm1;
mystr:TMemoryStream;
nowmyrec:myrec;
implementation
USES Rtti;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
rttiContext: TRttiContext;
rttiType: TRttiType;
fields: TArray<TRttiField>;
item: myrec;
i:word;
begin
mystr:=TMemoryStream.Create;
mystr.LoadFromFile(ExtractFilePath(Application.exename)+'1.data');
mystr.Position:=20;
mystr.readbuffer(nowmyRec,88);
rttiType := rttiContext.GetType(TypeInfo(myRec));
fields := rttiType.GetFields;
for i := low(fields) to high(fields) do
begin
Memo1.Lines.Add(fields[i].GetValue(@nowmyRec).ToString );
end;
end;
end.
myrec.name是中文字符,长度为64字节,我无法将myrec.name读入备忘录,请帮助我!
fields[i].GetValue(@nowmyRec).ToString
的代码替换为我的版本,该版本添加了IsArray
。然后它就可以正常工作了。 - David Heffernan