X
xuxincheng
Unregistered / Unconfirmed
GUEST, unregistred user!
主要代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
str:string;
begin
if opendialog1.Execute then
begin
str:=extractfilename(opendialog1.filename);
delete(str,pos('.',str),4);
with table1 do begin
open;
insert;
Fields[0].AsString:=str;
fields[1].asstring:=datetimetostr(date);
MyFile:=Tfilestream.create(opendialog1.FileName,fmopenread);
Stream := TBlobStream.Create(FieldByName('graphic') as TBlobField, bmWrite);
MemSize := MyFile.Size;
Inc(MemSize);
Buffer := AllocMem(MemSize);
try
Stream.Seek(0, soFromBeginning);
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
post;
showmessage('导入成功!');
end;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
astream:tblobstream;
fstream:tmemorystream;
begin
if savedialog1.Execute then
begin
fstream:=tmemorystream.Create;
astream:=tblobstream.Create(table1.fieldbyname('graphic') as tblobfield,bmread);
try
fstream.SetSize(astream.Size+1);
fstream.LoadFromStream(astream);
fstream.SaveToFile(savedialog1.FileName)
finally
astream.Free;
fstream.Free;
end;
showmessage('输出成功!');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
str:string;
begin
if opendialog1.Execute then
begin
str:=extractfilename(opendialog1.filename);
delete(str,pos('.',str),4);
with table1 do begin
open;
insert;
Fields[0].AsString:=str;
fields[1].asstring:=datetimetostr(date);
MyFile:=Tfilestream.create(opendialog1.FileName,fmopenread);
Stream := TBlobStream.Create(FieldByName('graphic') as TBlobField, bmWrite);
MemSize := MyFile.Size;
Inc(MemSize);
Buffer := AllocMem(MemSize);
try
Stream.Seek(0, soFromBeginning);
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
post;
showmessage('导入成功!');
end;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
astream:tblobstream;
fstream:tmemorystream;
begin
if savedialog1.Execute then
begin
fstream:=tmemorystream.Create;
astream:=tblobstream.Create(table1.fieldbyname('graphic') as tblobfield,bmread);
try
fstream.SetSize(astream.Size+1);
fstream.LoadFromStream(astream);
fstream.SaveToFile(savedialog1.FileName)
finally
astream.Free;
fstream.Free;
end;
showmessage('输出成功!');
end;
end;