恭参考
function TMainForm.Openword: Boolean;
var
Curword: string;
begin
Curword := GetRegString(HKEY_CLASSES_ROOT, '/word.Application/CurVer', '', '');
if Curword = '' then
begin
Application.MessageBox('请先安装 word 97 或 word 2000!',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
if (Curword <> 'word.Application.8') and (Curword <> 'word.Application.9') then
begin
Curword := GetRegString(HKEY_CLASSES_ROOT, '/word.Application.8', '', '');
if Curword = '' then
begin
Curword := GetRegString(HKEY_CLASSES_ROOT, '/word.Application.9', '', '');
if Curword <> '' then Curword := 'word.Application.9';
end
else
begin
Curword := 'word.Application.8';
end;
if Curword = '' then
begin
Application.MessageBox('无法运行 word 97 或 word 2000,' + #13#10
+ '请检查 word 97 或 word 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
end;
try
Fword := CreateOleObject(Curword);
if VarIsEmpty(Fword) then
begin
Application.MessageBox('无法运行 word 97 或 word 2000,' + #13#10
+ '请检查 word 97 或 word 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
except
Application.MessageBox('无法运行 word 97 或 word 2000,' + #13#10
+ '请检查 word 97 或 word 2000 是否已经正确安装。',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
Exit;
end;
try
begin
Fword.DisplayAlerts := False;
copyfile(pchar(ExtractFilePath(Application.Exename) + 'AnalyzeDB.mdl'),pchar(ExtractFilePath(Application.Exename) + 'AnalyzeDB.doc'),true);
SetCurrentDir(ExtractFilePath(Application.Exename));
Fdoc:=Fword.documents.Open(ExtractFilePath(Application.Exename) + 'AnalyzeDB.doc');
Fword.Visible := True;
Fword.Run('test',lbl_filename.text,lbl_password.Text );
Result := True;
end;
except
Application.MessageBox('分析失败,',
PChar(self.Caption), MB_OK + MB_ICONSTOP);
Result := False;
end;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
if not VarIsEmpty(Fword) then Fword.Quit;
end;