打开之前自己先建个临时文件,从数据库把数据读出来写进这个文件里
procedure Tsb_sbgl_wdmx.Button1Click(Sender: TObject);//文档信息按钮
var
fstr:string;
ldcid,lwdbm:string;
begin
if not DirectoryExists('c:/temp') then
MkDir('c:/temp');
fstr:='c:/temp/HDBFS_QWJS'+fdylx;//fdylx入库时对应的文件的后缀
ldcid:=fdcid;
lwdbm:=fwdbm;
try
tab_tb_wdgl_wdmx.open;
except
exit;
end;
if not tab_tb_wdgl_wdmx.Locate('dcid;wtbm',VarArrayOf([lDCID,lWDBM]),[]) then
exit;
ReadDbStream(fstr,tab_tb_wdgl_wdmx.FieldByName('wdmx') as TBlobField);
OpenTypeFile(fdylx,fstr);
end;
说明ReadDbStream
//Fname为文件名,BField为BLOB字段,成功反回true 否则为false
Function ReadDbStream(FName:string;BField: TBlobField):Boolean;
var
MemSize: Integer;
Buffer: PChar;
BStream: TBlobStream;
FHandle:HFile;
num
Word;
FDir:string;
begin
//如果文件存在则先删除
result:=true;
//判断路径
FDir:=copy(FName,0,GetPos('/',FName) - 1);
if not DirectoryExists(FDir) then
begin
//如果路径不存在,则创建C:/TEMP,文件名则相应改变
FDir:='c:/temp';
FName:=FDir + Copy(FName,GetPos('/',FName),length(FName) - GetPos('/',FName) + 1);
if not DirectoryExists(FDir) then
begin
if not ForceDirectories(FDir) then
begin
result:=false;
exit;
end;
end;
end;
if FileExists(FName) then DeleteFile(FName);
try
FHandle:=_lcreat(PChar(FName),0);
if (FHandle =INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('创建文件失败!','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
result:=false;
exit;
end;
try
BStream:=TBlobStream.Create(BField, bmRead);
MemSize := BStream.Size;
//加一字节放NULL字符
//Inc(MemSize);
try
Buffer := AllocMem(MemSize);
except
FreeMem(Buffer,MemSize);
Application.MessageBox('分配内存失败!','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
result:=false;
exit;
end;
BStream.Read(Buffer^,MemSize);
_llseek(FHandle,0,FILE_BEGIN);
_lwrite(FHandle,Buffer,MemSize);
finally
BStream.Free;
FreeMem(Buffer,MemSize);
end;
finally
_lclose(FHandle);
end;
end;
说明OpenTypeFile
//***extname后缀名,**************filename文件名
procedure OpenTypeFile(extname,filename:string);
function GetOpenFileCommand(ls_ext:string):string;
function GetCommand(ext,subkey:string):string;
var Reg:TRegistry;
str:string;
begin
if ext[1]<>'.' then ext:='.'+ext;
try
Reg:=TRegistry.Create;
Reg.RootKey:= HKEY_CLASSES_ROOT;
Reg.OpenKey(ext, True);
//读取类型值
str:=Reg.ReadString('');
Reg.CloseKey;
str:= str+subkey;
Reg.OpenKey(str, True);
//读取打开文件的程序
str:=Reg.ReadString('');
Reg.CloseKey;
finally
Reg.Free;
end;
result:=str;
end;
var str:string;
position:integer;
dir:Array[1..512] of char;
begin
str:=GetCommand(ls_ext,'/shell/Open/command');
if str = '' then
begin
str:=GetCommand(ls_ext,'/DefaultIcon');
end;
str:=string(StrUpper(pchar(str)));
position:=pos('%SYSTEMROOT%',str);
if position > 0 then
begin
FillChar(dir,512,32);
GetwindowsDirectory(@dir,512);
Delete(str,position,12);
insert(trim(string(dir)),str,position);
end;
position:=pos('.',str);
str:=copy(str,1,position+3);
position:=pos('"',str);
if position>0 then
begin
Delete(str,position,1);
end;
result:=str;
end;
var ls_command:string;
FDir:string;
begin
if extname = '' then
begin
Application.MessageBox('该文件类型不存在!','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
exit;
end;
ls_command:=GetOpenFileCommand(extname);
if not FileExists(ls_command) then
begin
Application.MessageBox('打开该类型文件的应用程序不存在!','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
exit;
end;
//判断路径
FDir:=copy(FileName,0,GetPos('/',FileName) - 1);
if not DirectoryExists(FDir) then
begin
//如果路径不存在,则创建C:/TEMP,文件名则相应改变
FDir:='c:/temp';
FileName:=FDir + Copy(FileName,GetPos('/',FileName),length(FileName) - GetPos('/',FileName) + 1);
if not DirectoryExists(FDir) then
begin
if not ForceDirectories(FDir) then
exit;
end;
end;
if not FileExists(FileName) then
begin
Application.MessageBox('要打开的文件不存在!','错误',MB_OKCANCEL+MB_ICONEXCLAMATION);
exit;
end;
winexec(pchar('"'+ls_command + '" "' + filename+'"' ),SW_SHOWNORMAL);
end;
申明 tab_TB_JCWH_WDMB.FieldByName('dylx').asstring:=copy(edit_wjlj.text,length(edit_wjlj.text)-3,4);
有问题,我只是对与word
取文件的后缀,就是调用类型。要查找‘.'你自己看看。
实际上我这个函数是用来对多媒体信息的,当然包括word