X
xwkp2008
Unregistered / Unconfirmed
GUEST, unregistred user!
我要将一个图片保存到一个type文件中
可是没有失败了
保存后还是只有type的内容
type
Pstuffer=^stuffer;
stuffer=packed record
num:string[20];
name:string[10];
password:string[20];
dept:string[50];
position:string[50];
tel:string[20];
email:string[100];
intro:string[255];
image:string[100];
size:int64;
end;
var dbfile:file of stuffer;
//保存
可是没有失败了
保存后还是只有type的内容
type
Pstuffer=^stuffer;
stuffer=packed record
num:string[20];
name:string[10];
password:string[20];
dept:string[50];
position:string[50];
tel:string[20];
email:string[100];
intro:string[255];
image:string[100];
size:int64;
end;
var dbfile:file of stuffer;
//保存
代码:
function savetodb(current:Pstuffer;route:string):string;
var fs:TfileStream;
var imagestream:TMemoryStream;
begin
imagestream:=TMemoryStream.Create;
imagestream.LoadFromFile(current^.image);
Current^.size:=imagestream.Size;
fs:=Tfilestream.Create(route,fmCreate);
fs.Position:=0;
fs.Write(Current^,sizeof(Current^));
fs.Position:=sizeof(current^);
fs.Write(imagestream,Current^.size);
fs.Free;
end;
//读取
function readfromdb(current:Pstuffer;route:string):boolean;
var fs:TfileStream;
var imagestream:TMemoryStream;
begin
imagestream:=TMemoryStream.Create;
fs:=Tfilestream.Create(route,fmOpenRead);
fs.Position:=0;
fs.Seek(0,soFromCurrent);
fs.Read(current^,sizeof(current^));
fs.Read(imagestream,current^.size);
imagestream.SaveToFile('db/'+current.image);
fs.Free;
end;