procedure showpicture(img: Timage; ADOQ: TADOQuery; field: string);
var MS: Tmemorystream;
begin
if not ADOQ.FieldByName(field).isnull then
begin
MS := TMemoryStream.Create;
try
TBlobField(ADOQ.FieldByName(field)).SaveToStream(MS);
MS.Position := 0; //注意
try
img.Picture.Graphic.LoadFromStream(MS);
except
//如果格式无效,则显示默认图片
on EInvalidGraphic do
img.Picture.Graphic := fmain.Image4.Picture.Graphic;
end;
finally
MS.Free;
end;
end
else
begin
MS := TMemoryStream.Create;
try
fmain.Image4.Picture.Graphic.SaveToStream(MS);
MS.Position := 0; //注意
img.Picture.Graphic.LoadFromStream(MS);
finally
MS.Free;
end;
end;
end;
procedure savepicture(img: Timage; ADOQ: TADOQuery; field: string);
var photo: Tmemorystream;
begin
photo := Tmemorystream.create;
img.Picture.graphic.savetoStream(photo);
Tblobfield(ADOQ.FieldByName(field)).loadfromstream(photo);
photo.Clear;
end;