javascript调用activex错误: JScript 中不支持的 Automation 类型 ( 积分: 100 )

  • 主题发起人 主题发起人 chenge
  • 开始时间 开始时间
C

chenge

Unregistered / Unconfirmed
GUEST, unregistred user!
请高手指点一下.
我写了一个activeform, 基本能运行. 但是javascript调用activex的方法的时候出错.错误信息如下:

Line:12
Char:1
Code:0
Error:变量使用了一个 JScript 中不支持的 Automation 类型
URL:file://E:/work/report/client/afxReportProj1.htm
====
调用代码:

function disp(url)
{
alert(url);
document.report.show(url)
//show是report控件的public方法, 出错的地方
alert('2');
}

<OBJECT
id=&quot;report&quot;
classid=&quot;clsid:CF75FFD4-FCBC-4B99-B9C3-024F1A15EC3F&quot;
codebase=&quot;./ReportClient.ocx#version=1,0,1,29&quot;
width=0
height=0
align=center
hspace=0
vspace=0
>
<param name=&quot;count&quot
value=&quot;100&quot;>
<param name=&quot;printonly&quot
value=&quot;false&quot;>
<param name=&quot;report&quot
value=&quot;http://localhost/?name=user&amp;type=fp3&quot;>
</OBJECT>
 
请高手指点一下.
我写了一个activeform, 基本能运行. 但是javascript调用activex的方法的时候出错.错误信息如下:

Line:12
Char:1
Code:0
Error:变量使用了一个 JScript 中不支持的 Automation 类型
URL:file://E:/work/report/client/afxReportProj1.htm
====
调用代码:

function disp(url)
{
alert(url);
document.report.show(url)
//show是report控件的public方法, 出错的地方
alert('2');
}

<OBJECT
id=&quot;report&quot;
classid=&quot;clsid:CF75FFD4-FCBC-4B99-B9C3-024F1A15EC3F&quot;
codebase=&quot;./ReportClient.ocx#version=1,0,1,29&quot;
width=0
height=0
align=center
hspace=0
vspace=0
>
<param name=&quot;count&quot
value=&quot;100&quot;>
<param name=&quot;printonly&quot
value=&quot;false&quot;>
<param name=&quot;report&quot
value=&quot;http://localhost/?name=user&amp;type=fp3&quot;>
</OBJECT>
 
把你的activeform申明部分贴出来看看才好诊断.
 
我发现普通的ActiveX,调用没有问题。下面是声明部分,不知道是否是你需要的?

type
TafxReport = class(TActiveForm, IafxReport)
Edit1: TEdit;
Button1: TButton;
IdHTTP1: TIdHTTP;
frxReport1: TfrxReport;
Memo1: TMemo;
Button2: TButton;
Label1: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
fvalue: integer;
freportname, fprintonly: string;
FEvents: IafxReportEvents;
procedure ActivateEvent(Sender: TObject);
procedure ClickEvent(Sender: TObject);
procedure CreateEvent(Sender: TObject);
procedure DblClickEvent(Sender: TObject);
procedure DeactivateEvent(Sender: TObject);
procedure DestroyEvent(Sender: TObject);
procedure KeyPressEvent(Sender: TObject
var Key: Char);
procedure PaintEvent(Sender: TObject);
protected
{ Protected declarations }
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage)
override;
procedure EventSinkChanged(const EventSink: IUnknown)
override;
function Get_Active: WordBool
safecall;
function Get_AlignDisabled: WordBool
safecall;
function Get_AutoScroll: WordBool
safecall;
function Get_AutoSize: WordBool
safecall;
function Get_AxBorderStyle: TxActiveFormBorderStyle
safecall;
function Get_Caption: WideString
safecall;
function Get_Color: OLE_COLOR
safecall;
function Get_DoubleBuffered: WordBool
safecall;
function Get_DropTarget: WordBool
safecall;
function Get_Enabled: WordBool
safecall;
function Get_Font: IFontDisp
safecall;
function Get_HelpFile: WideString
safecall;
function Get_KeyPreview: WordBool
safecall;
function Get_PixelsPerInch: Integer
safecall;
function Get_PrintScale: TxPrintScale
safecall;
function Get_Scaled: WordBool
safecall;
function Get_ScreenSnap: WordBool
safecall;
function Get_SnapBuffer: Integer
safecall;
function Get_Visible: WordBool
safecall;
function Get_VisibleDockClientCount: Integer
safecall;
procedure _Set_Font(var Value: IFontDisp)
safecall;
procedure Set_AutoScroll(Value: WordBool)
safecall;
procedure Set_AutoSize(Value: WordBool)
safecall;
procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle)
safecall;
procedure Set_Caption(const Value: WideString)
safecall;
procedure Set_Color(Value: OLE_COLOR)
safecall;
procedure Set_DoubleBuffered(Value: WordBool)
safecall;
procedure Set_DropTarget(Value: WordBool)
safecall;
procedure Set_Enabled(Value: WordBool)
safecall;
procedure Set_Font(const Value: IFontDisp)
safecall;
procedure Set_HelpFile(const Value: WideString)
safecall;
procedure Set_KeyPreview(Value: WordBool)
safecall;
procedure Set_PixelsPerInch(Value: Integer)
safecall;
procedure Set_PrintScale(Value: TxPrintScale)
safecall;
procedure Set_Scaled(Value: WordBool)
safecall;
procedure Set_ScreenSnap(Value: WordBool)
safecall;
procedure Set_SnapBuffer(Value: Integer)
safecall;
procedure Set_Visible(Value: WordBool)
safecall;
function Get_count: Integer
safecall;
procedure Set_count(Value: Integer)
safecall;
function Get_report: WideString
safecall;
procedure Set_report(const Value: WideString)
safecall;
function Get_printonly: WideString
safecall;
procedure Set_printonly(const Value: WideString)
safecall;
public
{ Public declarations }
procedure show(report: PChar)
safecall;
function Get_URL: PChar
safecall;
procedure Set_URL(Value: PChar)
safecall;

procedure Initialize
override;
end;
 
IafxReport的定义也贴出来啊.
 
在show后面发现问号,不知何故?

// *********************************************************************//
// Interface: IafxReport
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {8E27E131-2414-45B3-A866-CD703D955D70}
// *********************************************************************//
IafxReport = interface(IDispatch)
['{8E27E131-2414-45B3-A866-CD703D955D70}']
function Get_Visible: WordBool
safecall;
procedure Set_Visible(Value: WordBool)
safecall;
function Get_AutoScroll: WordBool
safecall;
procedure Set_AutoScroll(Value: WordBool)
safecall;
function Get_AutoSize: WordBool
safecall;
procedure Set_AutoSize(Value: WordBool)
safecall;
function Get_AxBorderStyle: TxActiveFormBorderStyle
safecall;
procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle)
safecall;
function Get_Caption: WideString
safecall;
procedure Set_Caption(const Value: WideString)
safecall;
function Get_Color: OLE_COLOR
safecall;
procedure Set_Color(Value: OLE_COLOR)
safecall;
function Get_Font: IFontDisp
safecall;
procedure Set_Font(const Value: IFontDisp)
safecall;
procedure _Set_Font(var Value: IFontDisp)
safecall;
function Get_KeyPreview: WordBool
safecall;
procedure Set_KeyPreview(Value: WordBool)
safecall;
function Get_PixelsPerInch: Integer
safecall;
procedure Set_PixelsPerInch(Value: Integer)
safecall;
function Get_PrintScale: TxPrintScale
safecall;
procedure Set_PrintScale(Value: TxPrintScale)
safecall;
function Get_Scaled: WordBool
safecall;
procedure Set_Scaled(Value: WordBool)
safecall;
function Get_Active: WordBool
safecall;
function Get_DropTarget: WordBool
safecall;
procedure Set_DropTarget(Value: WordBool)
safecall;
function Get_HelpFile: WideString
safecall;
procedure Set_HelpFile(const Value: WideString)
safecall;
function Get_ScreenSnap: WordBool
safecall;
procedure Set_ScreenSnap(Value: WordBool)
safecall;
function Get_SnapBuffer: Integer
safecall;
procedure Set_SnapBuffer(Value: Integer)
safecall;
function Get_DoubleBuffered: WordBool
safecall;
procedure Set_DoubleBuffered(Value: WordBool)
safecall;
function Get_AlignDisabled: WordBool
safecall;
function Get_VisibleDockClientCount: Integer
safecall;
function Get_Enabled: WordBool
safecall;
procedure Set_Enabled(Value: WordBool)
safecall;
procedure show(report: PChar)
safecall;
procedure Set_URL(Param1: PChar)
safecall;
function Get_count: Integer
safecall;
procedure Set_count(Value: Integer)
safecall;
function Get_report: WideString
safecall;
procedure Set_report(const Value: WideString)
safecall;
function Get_printonly: WideString
safecall;
procedure Set_printonly(const Value: WideString)
safecall;
property Visible: WordBool read Get_Visible write Set_Visible;
property AutoScroll: WordBool read Get_AutoScroll write Set_AutoScroll;
property AutoSize: WordBool read Get_AutoSize write Set_AutoSize;
property AxBorderStyle: TxActiveFormBorderStyle read Get_AxBorderStyle write Set_AxBorderStyle;
property Caption: WideString read Get_Caption write Set_Caption;
property Color: OLE_COLOR read Get_Color write Set_Color;
property Font: IFontDisp read Get_Font write Set_Font;
property KeyPreview: WordBool read Get_KeyPreview write Set_KeyPreview;
property PixelsPerInch: Integer read Get_PixelsPerInch write Set_PixelsPerInch;
property PrintScale: TxPrintScale read Get_PrintScale write Set_PrintScale;
property Scaled: WordBool read Get_Scaled write Set_Scaled;
property Active: WordBool read Get_Active;
property DropTarget: WordBool read Get_DropTarget write Set_DropTarget;
property HelpFile: WideString read Get_HelpFile write Set_HelpFile;
property ScreenSnap: WordBool read Get_ScreenSnap write Set_ScreenSnap;
property SnapBuffer: Integer read Get_SnapBuffer write Set_SnapBuffer;
property DoubleBuffered: WordBool read Get_DoubleBuffered write Set_DoubleBuffered;
property AlignDisabled: WordBool read Get_AlignDisabled;
property VisibleDockClientCount: Integer read Get_VisibleDockClientCount;
property Enabled: WordBool read Get_Enabled write Set_Enabled;
property URL: PChar write Set_URL;
property count: Integer read Get_count write Set_count;
property report: WideString read Get_report write Set_report;
property printonly: WideString read Get_printonly write Set_printonly;
end;

// *********************************************************************//
// DispIntf: IafxReportDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {8E27E131-2414-45B3-A866-CD703D955D70}
// *********************************************************************//
IafxReportDisp = dispinterface
['{8E27E131-2414-45B3-A866-CD703D955D70}']
property Visible: WordBool dispid 201;
property AutoScroll: WordBool dispid 202;
property AutoSize: WordBool dispid 203;
property AxBorderStyle: TxActiveFormBorderStyle dispid 204;
property Caption: WideString dispid -518;
property Color: OLE_COLOR dispid -501;
property Font: IFontDisp dispid -512;
property KeyPreview: WordBool dispid 205;
property PixelsPerInch: Integer dispid 206;
property PrintScale: TxPrintScale dispid 207;
property Scaled: WordBool dispid 208;
property Active: WordBool readonly dispid 209;
property DropTarget: WordBool dispid 210;
property HelpFile: WideString dispid 211;
property ScreenSnap: WordBool dispid 212;
property SnapBuffer: Integer dispid 213;
property DoubleBuffered: WordBool dispid 214;
property AlignDisabled: WordBool readonly dispid 215;
property VisibleDockClientCount: Integer readonly dispid 216;
property Enabled: WordBool dispid -514;
procedure show(report: {??PChar}OleVariant)
dispid 217;
property URL: {??PChar}OleVariant writeonly dispid 218;
property count: Integer dispid 219;
property report: WideString dispid 220;
property printonly: WideString dispid 221;
end;

// *********************************************************************//
// DispIntf: IafxReportEvents
// Flags: (4096) Dispatchable
// GUID: {7F408E93-5A81-48CF-A3BE-A970FA330C6A}
// *********************************************************************//
IafxReportEvents = dispinterface
['{7F408E93-5A81-48CF-A3BE-A970FA330C6A}']
procedure OnActivate
dispid 201;
procedure OnClick
dispid 202;
procedure OnCreate
dispid 203;
procedure OnDblClick
dispid 204;
procedure OnDestroy
dispid 205;
procedure OnDeactivate
dispid 206;
procedure OnKeyPress(var Key: Smallint)
dispid 207;
procedure OnPaint
dispid 208;
end;


// *********************************************************************//
// OLE Control Proxy class declaration
// Control Name : TafxReport
// Help String : afxReport Control
// Default Interface: IafxReport
// Def. Intf. DISP? : No
// Event Interface: IafxReportEvents
// TypeFlags : (34) CanCreate Control
// *********************************************************************//
TafxReportOnKeyPress = procedure(ASender: TObject
var Key: Smallint) of object;

TafxReport = class(TOleControl)
private
FOnActivate: TNotifyEvent;
FOnClick: TNotifyEvent;
FOnCreate: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnDestroy: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnKeyPress: TafxReportOnKeyPress;
FOnPaint: TNotifyEvent;
FIntf: IafxReport;
function GetControlInterface: IafxReport;
protected
procedure CreateControl;
procedure InitControlData
override;
procedure Set_URL(Param1: PChar);
public
procedure show(report: PChar);
property ControlInterface: IafxReport read GetControlInterface;
property DefaultInterface: IafxReport read GetControlInterface;
property Visible: WordBool index 201 read GetWordBoolProp write SetWordBoolProp;
property Active: WordBool index 209 read GetWordBoolProp;
property DropTarget: WordBool index 210 read GetWordBoolProp write SetWordBoolProp;
property HelpFile: WideString index 211 read GetWideStringProp write SetWideStringProp;
property ScreenSnap: WordBool index 212 read GetWordBoolProp write SetWordBoolProp;
property SnapBuffer: Integer index 213 read GetIntegerProp write SetIntegerProp;
property DoubleBuffered: WordBool index 214 read GetWordBoolProp write SetWordBoolProp;
property AlignDisabled: WordBool index 215 read GetWordBoolProp;
property VisibleDockClientCount: Integer index 216 read GetIntegerProp;
property Enabled: WordBool index -514 read GetWordBoolProp write SetWordBoolProp;
property URL: PChar write Set_URL;
published
property Anchors;
property ParentColor;
property ParentFont;
property Align;
property DragCursor;
property DragMode;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDrag;
property AutoScroll: WordBool index 202 read GetWordBoolProp write SetWordBoolProp stored False;
property AutoSize: WordBool index 203 read GetWordBoolProp write SetWordBoolProp stored False;
property AxBorderStyle: TOleEnum index 204 read GetTOleEnumProp write SetTOleEnumProp stored False;
property Caption: WideString index -518 read GetWideStringProp write SetWideStringProp stored False;
property Color: TColor index -501 read GetTColorProp write SetTColorProp stored False;
property Font: TFont index -512 read GetTFontProp write SetTFontProp stored False;
property KeyPreview: WordBool index 205 read GetWordBoolProp write SetWordBoolProp stored False;
property PixelsPerInch: Integer index 206 read GetIntegerProp write SetIntegerProp stored False;
property PrintScale: TOleEnum index 207 read GetTOleEnumProp write SetTOleEnumProp stored False;
property Scaled: WordBool index 208 read GetWordBoolProp write SetWordBoolProp stored False;
property count: Integer index 219 read GetIntegerProp write SetIntegerProp stored False;
property report: WideString index 220 read GetWideStringProp write SetWideStringProp stored False;
property printonly: WideString index 221 read GetWideStringProp write SetWideStringProp stored False;
property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
property OnKeyPress: TafxReportOnKeyPress read FOnKeyPress write FOnKeyPress;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
end;
 
我也不懂,帮你顶
 
你的activeform注册了没有?
 
不存在注册的问题。
如果没有注册,错误肯定不一样。
 
可能是不支持pchar,你换成WideString看看.
 
改变为widestring后,关于automation的错误信息消失了。
两个alert都出来了,但是那个show似乎还是没有反应。
 
show的实现贴出来看看才知道了.
 
procedure TafxReport.show(report: widestring);
var
fn: string;
//ms:TMemoStream;
begin
showmessage('show in activex 1216');
//edit1.Text:='http://localhost/?name=sale&amp;type=fp3'
//report
//'e:/view.fp3';
fn := 'c:/view.fp3';
//showmessage(fn);

//memo1.Text:=self.IdHTTP1.Get(edit1.Text);

memo1.Text := self.IdHTTP1.Get(freportName);
self.Memo1.Lines.SaveToFile(fn);
self.frxReport1.PreviewPages.LoadFromFile(fn);

if fprintonly = 'true' then
self.frxReport1.Print
else
self.frxReport1.ShowPreparedReport;
end;
 
你调试下看看 showmessage('show in activex 1216');这句执行到没有.
 
设置了断点,没有执行到!
 
把object标签放到函数的前面去看看.
 
没有效果,还是从原理上分析一下吧。

你是否有activeform调用成功的例子。
在mastering delphi 7书中有一个activex control的例子,我测试过,调用没有问题。

activeform和activex control有什么区别?
 
不带参数的调用成功了!
 
这样啊,我还在给你找例子呢.把所有参数换成olevariant的看看.
 
成功了!可能是原来那个SHOW方法的定义的问题。

谢谢satanmonkey。
 
后退
顶部