请帮忙看一下如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
WordApp: OleVariant;
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, Oforward, wrap, format, replacewith, replace,
matchchashida,matchdiacritics,matchalef,matchcontrol: olevariant;
MyDoc:TWordDocument;
begin
WordApp := CreateOleObject('Word.Application');
WordApp.Documents.Open (FileName:='F:\归还投资款项协议书.doc', ReadOnly:=False); 
findtext := '< #name> ';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
Oforward := true;
wrap := wdfindcontinue;
format := false;
replacewith := '易达置业管理有限公司';
replace := true;
MyDoc.range.find.execute( findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms, Oforward,
wrap, format, replacewith, replace,
matchchashida,matchdiacritics,matchalef, matchcontrol );
end;
end.
错误提示:[Warning] Unit1.pas(56): Variable 'MyDoc' might not have been initialized  

解决方案 »

  1.   

    FWordApp.Documents.Open(TemplateFileName);
      

  2.   

    完整一点的:unit WordManage;interfaceuses
      Windows, Messages, SysUtils, Variants, Forms, Classes, ComObj;type
      TWordManage=class
      private
        FWordApp:Variant;
        FWordDoc:Variant;
      public
        function Initialzie():Boolean;
        function NewDoc(TemplateFileName:String):Boolean;
        function SetText(Token:String;Value:String):Boolean;
      end;implementationfunction TWordManage.Initialzie():Boolean;
    begin
      Result:=false;
      try
        FWordApp:=CreateOleObject('Word.Application');
        FWordApp.Visible:=true;
        Result:=true;
      except
        on E:Exception do begin
          MessageBox(Application.Handle,pchar(E.Message),pchar(Application.Title),MB_ICONERROR);
          FWordApp:=UnAssigned;
        end;
      end;
    end;function TWordManage.NewDoc(TemplateFileName:String):Boolean;
    begin
      FWordApp.Documents.Open(TemplateFileName);
      FWordDoc:=FWordApp.ActiveDocument;
      Result:=true;
    end;function TWordManage.SetText(Token:String;Value:String):Boolean;
    var
      FindText,MatchCase,MatchWholeWord,MatchWildcards,MatchSoundsLike,
      MatchAllWordForms,Forward,Wrap,Format,ReplaceWith,Replace,
      MatchKashida,MatchDiacritics,MatchAlefHamza,MatchControl:Variant;
    begin
      FindText:=Token;
      MatchCase:=false;
      MatchWholeWord:=true;
      MatchWildcards:=false;
      MatchSoundsLike:=false;
      MatchAllWordForms:=false;
      Forward:=true;
      Wrap:=1;
      Format:=false;
      ReplaceWith:=Value;
      Replace:=true;
      MatchKashida:=false;
      MatchDiacritics:=false;
      MatchAlefHamza:=false;
      MatchControl:=false;  FWordDoc.Range.Find.Execute(FindText,MatchCase,MatchWholeWord,
          MatchWildcards,MatchSoundsLike,MatchAllWordForms,Forward,
          Wrap,Format,ReplaceWith,Replace);
      Result:=true;
    end;end.
      

  3.   

    to: tonylk(=www.tonixsoft.com=) 错误提示:'invalid variant operation '