procedure TForm1.Button1Click(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
MyFile:=Tfilestream.create('c:/1.doc',fmopenread);
with table1 do
begin
Open;
insert;
Stream := TBlobStream.Create(FieldByName('content') as TBlobField, bmWrite);{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Seek(0, soFromBeginning); {Seek 0 bytes from the stream's end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
{ if HandelException(E)<>0 then
exit
else
raise;
end;
exit; }
end;
Doc_ole.CreateObjectFromFile('c:/1.doc',False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;