查了很多贴子但是没有找到解决问题的。
最近老板要我做一个程序,说起来很简单,就是开发一个word文件阅读器,这个阅读器可以打开Word文档,允许查看内容但不能编辑文档的内容。我用TOleContainer来做,代码如下:
    MyWordOLE.DestroyObject;
    MyWordOLE.CreateObject('Word.Document',false);
    MyWordOLE.DoVerb(ovInPlaceActivate);
    OLEObj:=MyWordOLE.OleObject;
    //下面代码用于隐藏word的工具栏
    nCmdBarCount:=OLEObj.OlePropertyGet('CommandBars').OlePropertyGet('Count');
    for I := 0 to nCmdBarCount - 1 do
    begin
      OLEObj.OlePropertyGet('CommandBars',i+1).OlePropertySet('Enabled',false);
    end;MyWordOLE是TOleContainer。
问题出在隐藏word工具栏的代码,运行程序后提示Method 'OlePropertyGet' not supported by automation object。

解决方案 »

  1.   

    OlePropertyGet方法不被automation object支持?
    换用COM object试试?
      

  2.   

    Delphi中操作OLE对象和C++Builder中的略有区别:    nCmdBarCount := OLEObj.CommandBars.Count;
        for I := 0 to nCmdBarCount - 1 do
        begin
          OLEObj.CommandBars(i+1).Enabled := false;
        end;
      

  3.   

    sorry,上面的代码有笔误,应该这样:    nCmdBarCount := OLEObj.CommandBars.Count;
        for I := 0 to nCmdBarCount - 1 do
        begin
          OLEObj.CommandBars[i+1].Enabled := false;
        end;另外需要提醒一下,Office2007以后的版本中,由于采用了Ribbon风格的工具栏,所以实现的效果可能和Office2003有区别.
      

  4.   

    非常感谢ccrun,我确实是从其他帖子里的C++Builder的代码转的,好像那个帖子也是你写的,呵呵。
    再次感谢,希望以后有问题能多多赐教。