先在form 里放一个olecontainer(Ole_Word),然后在其中放一个菜单(menu1).
菜单上加一个mnu_pro菜单项目,然后
......
....
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
mnu_verbs:Array[0..100] of TMenuitem;
VerbCount:integer;
procedure ItemClick(Sender:TObject);.
....
....
procedure TRptForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Ole_word.DestroyObject;
end;
procedure TRptForm2.ItemClick(Sender:TObject);
begin
Ole_Word.DoVerb((sender as TMenuItem).Tag);
end;
procedure TRptForm2.FormActivate(Sender: TObject);
var
i:integer;
//VerbCount:integer;
begin
if RptFileName='' then exit;
if not FileExists(RptFileName) then
begin
ShowMessage('文件不存在!');
exit;
end;
Ole_Word.CreateObjectFromFile(RptFileName,true);
try
for i:=0 to VerbCount do
if mnu_verbs<>nil then
begin
mnu_proc.delete(0);
mnu_verbs.free;
mnu_verbs:=nil;
end;
VerbCount:=ole_word.ObjectVerbs.Count;
if VerbCount<>0 then
for i:=0 to VerbCount-1 do
begin
mnu_verbs:=Tmenuitem.Create(self);
mnu_verbs.caption:=Ole_word.ObjectVerbs;
mnu_Verbs.tag:=i;
mnu_verbs.onclick:=ItemClick;
mnu_proc.Add(mnu_verbs);
end;
except
ShowMessage('Microsoft word error!');
end;
end;