//按单字节反转内存的函数 procedure ReverseMemory(P: PByte; Len: Integer); overload; var B: Byte; P2: PByte; begin P2 := P; Inc(P2, Len - 1); while Integer(P) < Integer(P2) do begin B := P^; P^ := P2^; P2^ := B; Inc(P); Dec(P2); end; end; //按双字节反转内存的函数 procedure ReverseMemory(P: PWord; Len: Integer); overload; var W: Word; P2: PWord; begin P2 := P; Inc(P2, Len div 2 - 1); while Integer(P) < Integer(P2) do begin W := P^; P^ := P2^; P2^ := W; Inc(P); Dec(P2); end; end; //按四字节反转内存的函数 procedure ReverseMemory(P: PInteger; Len: Integer); overload; var I: Integer; P2: PInteger; begin P2 := P; Inc(P2, Len div 4 - 1); while Integer(P) < Integer(P2) do begin I := P^; P^ := P2^; P2^ := I; Inc(P); Dec(P2); end; end; //调用测试 procedure TForm1.Button1Click(Sender: TObject); var bs: TBytes; i: Integer; begin SetLength(bs, 8); for i := 0 to Length(bs) - 1 do bs[i] := i + 49; ShowMessage(StringOf(bs)); {12345678} for i := 0 to Length(bs) - 1 do bs[i] := i + 49; ReverseMemory(PByte(bs), Length(bs)); ShowMessage(StringOf(bs)); {87654321} for i := 0 to Length(bs) - 1 do bs[i] := i + 49; ReverseMemory(PWord(bs), Length(bs)); ShowMessage(StringOf(bs)); {78563412} for i := 0 to Length(bs) - 1 do bs[i] := i + 49; ReverseMemory(PInteger(bs), Length(bs)); ShowMessage(StringOf(bs)); {56781234} end;
分类:
常用自定义函数、单元
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2008-11-12 在 Delphi 2009 中, for in 循环都能用在什么地方?
2008-11-12 写在博客一周年
2007-11-12 测试代码
2007-11-12 祝贺我的博客开通!