delphi 写内存问题 送上我所有的的分
来源:百度知道 编辑:UC知道 时间:2024/05/22 23:54:54
我要定义个一个 记录 把这个 记录 送进内存后记录里面的内存格式为
前四位为字符串长度后面的是和字符串一样的内存数据
比如 字符串 0123456789ABCDEF
把记录送进内存后 内存的数据为 0F 00 01 23 45 67 89 AB CD EF
应该怎么写 大家给帮帮忙 我把所有的的分都送上了
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure SendToMem(S:String;AStream:TMemoryStream);
implementation
{$R *.dfm}
procedure SendToMem(S:String;AStream:TMemoryStream);
var
I,Buf: Integer;
L:Word;
A:Array of Byte;
begin
L:=Length(S);
AStream.WriteBuffer(L,sizeof(L));
SetLength(A,L div 2);
I:=1;
while I<=L do
begin
Buf:= StrToInt('$'+S[I]+S[I+1]);
AStream.WriteBuffer(Buf,1);
inc(I,2);
end;
end;
proce