我写了一个小COM组件,Automation Object类型的。
想在HTML里用JavaScript或VbScript调用。但是,脚本创建都成功,但是在调用里同的功能函数时,老是报Object doesn't support this property or method错,这是怎么回事????但是JavaScript调用像M$的MSXML等都是可以的。为什么调用自己开发的就报错。

解决方案 »

  1.   

    COMTest_TLB.Pasunit ComTest_TLB;// ************************************************************************ //
    // WARNING                                                                    
    // -------                                                                    
    // The types declared in this file were generated from data read from a       
    // Type Library. If this type library is explicitly or indirectly (via        
    // another type library referring to this type library) re-imported, or the   
    // 'Refresh' command of the Type Library Editor activated while editing the   
    // Type Library, the contents of this file will be regenerated and all        
    // manual modifications will be lost.                                         
    // ************************************************************************ //// PASTLWTR : 1.2
    // File generated on 2006-3-31 9:50:22 from Type Library described below.// ************************************************************************  //
    // Type Lib: E:\COMTest\ComTest.tlb (1)
    // LIBID: {C77D8814-2210-45EC-9807-CDA47BA51ADB}
    // LCID: 0
    // Helpfile: 
    // HelpString: ComTest Library
    // DepndLst: 
    //   (1) v2.0 stdole, (C:\WINDOWS\system32\stdole2.tlb)
    // ************************************************************************ //
    {$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. 
    {$WARN SYMBOL_PLATFORM OFF}
    {$WRITEABLECONST ON}
    {$VARPROPSETTER ON}
    interfaceuses Windows, ActiveX, Classes, Graphics, StdVCL, Variants;
      // *********************************************************************//
    // GUIDS declared in the TypeLibrary. Following prefixes are used:        
    //   Type Libraries     : LIBID_xxxx                                      
    //   CoClasses          : CLASS_xxxx                                      
    //   DISPInterfaces     : DIID_xxxx                                       
    //   Non-DISP interfaces: IID_xxxx                                        
    // *********************************************************************//
    const
      // TypeLibrary Major and minor versions
      ComTestMajorVersion = 1;
      ComTestMinorVersion = 0;  LIBID_ComTest: TGUID = '{C77D8814-2210-45EC-9807-CDA47BA51ADB}';  IID_ITestCom: TGUID = '{C94E11C0-D4E8-44A6-9527-8FC1BB16ED45}';
      CLASS_TestCom: TGUID = '{91142AD6-407B-496A-A037-8B289B86593F}';
    type// *********************************************************************//
    // Forward declaration of types defined in TypeLibrary                    
    // *********************************************************************//
      ITestCom = interface;
      ITestComDisp = dispinterface;// *********************************************************************//
    // Declaration of CoClasses defined in Type Library                       
    // (NOTE: Here we map each CoClass to its Default Interface)              
    // *********************************************************************//
      TestCom = ITestCom;
    // *********************************************************************//
    // Interface: ITestCom
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {C94E11C0-D4E8-44A6-9527-8FC1BB16ED45}
    // *********************************************************************//
      ITestCom = interface(IDispatch)
        ['{C94E11C0-D4E8-44A6-9527-8FC1BB16ED45}']
        function HuHU: OleVariant; safecall;
      end;// *********************************************************************//
    // DispIntf:  ITestComDisp
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {C94E11C0-D4E8-44A6-9527-8FC1BB16ED45}
    // *********************************************************************//
      ITestComDisp = dispinterface
        ['{C94E11C0-D4E8-44A6-9527-8FC1BB16ED45}']
        function HuHU: OleVariant; dispid 201;
      end;// *********************************************************************//
    // The Class CoTestCom provides a Create and CreateRemote method to          
    // create instances of the default interface ITestCom exposed by              
    // the CoClass TestCom. The functions are intended to be used by             
    // clients wishing to automate the CoClass objects exposed by the         
    // server of this typelibrary.                                            
    // *********************************************************************//
      CoTestCom = class
        class function Create: ITestCom;
        class function CreateRemote(const MachineName: string): ITestCom;
      end;implementationuses ComObj;class function CoTestCom.Create: ITestCom;
    begin
      Result := CreateComObject(CLASS_TestCom) as ITestCom;
    end;class function CoTestCom.CreateRemote(const MachineName: string): ITestCom;
    begin
      Result := CreateRemoteComObject(MachineName, CLASS_TestCom) as ITestCom;
    end;end.
      

  2.   

    Unit1.pas
    {$WARN SYMBOL_PLATFORM OFF}interfaceuses
      ComObj, ActiveX, ComTest_TLB, StdVcl;type
      TTestCom = class(TAutoObject, ITestCom)
      protected
        function HuHU: OleVariant; safecall;  end;implementationuses ComServ;function TTestCom.HuHU: OleVariant;
    begin
      Result := 'HaHaHaHa';
    end;initialization
      TAutoObjectFactory.Create(ComServer, TTestCom, Class_TestCom,
        ciMultiInstance, tmApartment);
    end.
      

  3.   

    HTML.html
    <HTML><HEAD>
    <META NAME="GENERATOR" CONTENT="Microsoft FrontPage 6.0">
    <META NAME="ProgId" CONTENT="FrontPage.Editor.Document">
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
    <TITLE>新建网页 1</TITLE>
    <SCRIPT LANGUAGE="javascript"> function ss() {
    try {
    var s = new ActiveXObject("ComTest.TestCom");
    var z;
    z = s.HuHU;
    alert(z);
    }catch(e){
    alert(e.message)
    }
    }

    </SCRIPT>
    </HEAD><BODY>

    <INPUT TYPE="button" VALUE="按钮" NAME="B3" onclick="ss();"></BODY></HTML>
      

  4.   

    先用DELPHI代码试试能不能调用...uses comobj;procedure TForm1.Button1Click(Sender: TObject);
    var
      o:Variant;
    begin
      o:=CreateOleObject('ComTest.TestCom');
      ShowMessage(o.HuHu);
      

  5.   

    谢谢楼上的,
    我用Delphi试过了,是成功的。
    procedure TForm2.Button1Click(Sender: TObject);
    var s: Variant;
    begin
    s :=  CreateOleObject('ComTest.TestCom');ShowMessage(VarToStr( s.HuHU));
    end;end.
      

  6.   

    有没有注册COM组件呀, regSVR32 dll名称
      

  7.   

    晕死.....z = s.HuHU;//这样JS会把它当成属性.
    改为:
    z = s.HuHU();//这样JS才会把它当成方法调用.