我的代码是这样的:
if adodataset2.Locate('FNXM',Edit1.Text,[]) then
begin
GetMem(p,1024);
ms:=adodataset2.CreateBlobStream(adodataset2.FieldByName('Template'),bmRead);
ms.Read(p^,1024);
Fms.Write(p^,1024);
freemem(p);
Fms.Position:=0;
GetMem(p,1024);
move(fms.Memory^,p^,1024);
label6.Caption:=inttostr(p^);
end;
这段代码执行后能得到我想要的结果吗?
如果最后一条语句为
label6.Caption:=inttostr(integer(p));则每点击一次按钮内容变化一次,依次为输入下一条记录的'FNBM'时应该显示的内容。这是什么原因呢。
if adodataset2.Locate('FNXM',Edit1.Text,[]) then
begin
GetMem(p,1024);
ms:=adodataset2.CreateBlobStream(adodataset2.FieldByName('Template'),bmRead);
ms.Read(p^,1024);
Fms.Write(p^,1024);
freemem(p);
Fms.Position:=0;
GetMem(p,1024);
move(fms.Memory^,p^,1024);
label6.Caption:=inttostr(p^);
end;
这段代码执行后能得到我想要的结果吗?
如果最后一条语句为
label6.Caption:=inttostr(integer(p));则每点击一次按钮内容变化一次,依次为输入下一条记录的'FNBM'时应该显示的内容。这是什么原因呢。
begin
try
tempstream:=TStringStream.Create('');
TBlobField(adodataset2.FieldByName('Template')).SaveToStream(tempstream);
label6.Caption:= tempstream.datastring;
finally
tempstream.Free;
end;
end;
label6.Caption:=inttostr(p^); 这个只是第一个字节的内容,要用Inc(P)继续向后取内容
再用IntToHex(p^)转成十六进制显示。
label6.Caption:=inttostr(integer(p)); 这个是当前指针的地址,而不是内容
如果数据库中保存的是二进制数据,尽管label6.Caption:=inttostr(p^); 只是第一个字节的内容,那他也应该是二进制的啊,难道二进制中除了01以为还有其他的数据吗?
再给个函数给你
function StrToHex(s: string): string;
var
i, len: integer;
hex: string;
begin
hex := '';
len := length(s);
for i := 1 to len do
hex := hex + inttohex(ord(s[i]), 2);
result := hex;
end;你把label6.Caption:= tempstream.datastring; 改为label6.Caption:= StrToHex(tempstream.datastring);