// 定义结构体
type
TmyRec= record
name:string[10];
password:string[10];
end;
function RawToBytes(const AValue; const ASize: Integer): TBytes;
begin
SetLength(Result, ASize);
if ASize > 0 then begin
Move(AValue, Result[0], ASize);
end;
end;
procedure BytesToRaw(const AValue: TBytes; var VBuffer; const ASize: Integer);
begin
Assert(Length(AValue) >= ASize);
Move(AValue[0], VBuffer, ASize);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
rec: TmyRec;
rec2: TmyRec;
db:TBytes;
begin
rec.name :='cxg';
rec.password:='929';
// 序列结构体为bytes
db := RawToBytes(rec, SizeOf(rec));
// bytes还原结构体
BytesToRaw(db, rec2, SizeOf(rec2));
Caption := rec2.name+'\'+rec2.password;
end;
http://www.cnblogs.com/hnxxcxg/p/4253919.html