结构体的序列和还原(使用Move方法)
2024-09-10 20:36:28
// 定义结构体
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
最新文章
- netfx_NativeCompilation.msi 传说中的 .NET Native 预览版的文件列表
- High Aavialability with Group Replication-by宋利兵
- Spring使用p名称空间配置属性
- Linux下mysql自动备份
- ASP.NET中App_Code,App_Data等文件夹的作用
- SQLite学习第01天:参考资料
- injector
- sqlserver 分页查询总结
- .NET开发邮件发送功能
- hdu 2157 How many ways?? (可达矩阵)
- intra调用order
- WinAPI 字符及字符串函数(5): IsCharAlpha - 是否是个字母
- Kong安装教程(v1.0.2)
- 自学Linux Shell10.1-使用编辑器vim
- linux 下git使用教程
- [py]python中的==和is的区别
- jni 找不到本地方法的实现
- NavRouter
- 常用HTML标签的全称及描述
- Disillusioning #1 水题+原题赛(被虐瞎)