关于用delphi开发ocx控件,无法调用公开的方法 现有一需求,打算在网页上调用一个ocx控件,这个控件负责取客户端机器上的网卡MAC地址.所以想开发这个控件.自己根据网上查来的资料做了一个,但是不知道为什么,我自己增加的方法GetMAC(已放在public公开),但是在网页上调用时,却无法找到这个公开的方法GetMAC.请高开指教!先谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有个朋友正在搞跟你类似的东东,你俩可以讨论讨论http://topic.csdn.net/u/20090423/08/0bab3642-4e07-423c-969e-d258006f1da0.html?seed=1323670561另外,你咋不贴代码呢,这么说,谁知道咋回事啊! unit myocxformImpl1;{$WARN SYMBOL_PLATFORM OFF}interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ActiveX, AxCtrls, myocxformProj1_TLB, StdVcl;type Tmyocxform = class(TActiveForm, Imyocxform) private { Private declarations } FEvents: ImyocxformEvents; 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; public { Public declarations } procedure Initialize; override; procedure GetTest(a: Integer; out b: OleVariant); safecall; end;implementationuses ComObj, ComServ;{$R *.DFM}{ Tmyocxform }procedure Tmyocxform.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);begin { Define property pages here. Property pages are defined by calling DefinePropertyPage with the class id of the page. For example, DefinePropertyPage(Class_myocxformPage); }end;........procedure Tmyocxform.Set_ScreenSnap(Value: WordBool);begin ScreenSnap := Value;end;procedure Tmyocxform.Set_SnapBuffer(Value: Integer);begin SnapBuffer := Value;end;procedure Tmyocxform.Set_Visible(Value: WordBool);begin Visible := Value;end;procedure Tmyocxform.GetTest(a: Integer; out b: OleVariant);begin b := a + random(10000);end;initialization TActiveFormFactory.Create( ComServer, TActiveFormControl, Tmyocxform, Class_myocxform, 1, '', OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL, tmApartment);end.此外,添加的方法都是procedure,可以加function函數嗎? 里面的GetTest(),在別人調用的時候,沒有公布出來 你自己写在public里面的方法是没有用的,别人没法调用的,只能在接口中声明才可以的。声明接口后,会自动在单元文件中增加相应的实现方法,你实现这个方法就可以了 我用的D7,我接口里面聲明了呀 Tmyocxform = class(TOleControl) private FOnActivate: TNotifyEvent; FOnClick: TNotifyEvent; FOnCreate: TNotifyEvent; FOnDblClick: TNotifyEvent; FOnDestroy: TNotifyEvent; FOnDeactivate: TNotifyEvent; FOnKeyPress: TmyocxformOnKeyPress; FOnPaint: TNotifyEvent; FIntf: Imyocxform; function GetControlInterface: Imyocxform; protected procedure CreateControl; procedure InitControlData; override; public procedure GetTest(a: Integer; out b: OleVariant);//这是我加的方法 property ControlInterface: Imyocxform read GetControlInterface; property DefaultInterface: Imyocxform 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; 1.view-type library--olgn右键--添加属性svrip,类型bstr2.找到svrip的get,set代码自定义一个全局变量var sSvrIP:stringimplemention ....修改Set,get过程:function ToLgn.Get_SvrIP: WideString;begin result:=sSvrIP;end;procedure ToLgn.Set_SvrIP(const Value: WideString);begin sSvrIP:=Value;end;注:不会自动生成变量处理代码,不自己写,将来使用Get_SvrIP根本收不到网页穿过来的变量值。3.网页调用形式<OBJECT classid="clsid:CC721C00-9C4B-42DC-B3F6-4C78DDFD4A1E" codebase="GetIP.ocx"><param name="MyIP" value="192.168.0.3"></OBJECT> 发现新问题,定义不出来WideString,手工改成这个类型,会自动变回去.还有怎么测试程序是否正确呢?如何把这个Get_SvrIP的返回值在网页上显示出来?我要实现的功能是:做个ocx控件,取IE客户端的机器MAC物理地址,然后回传给服务器,服务器根据这个MAC地址来判断该机器是否有权登录这个系统(用户要求指定某台机器才能使用系统)再加50分,谢谢各位!!! 为什么我在Delphi7中不能调用ConnectToPrinterDlg函数,总是说没有声明,而网上很多人都可以用呢? 如果用Delphi,在win2000或winxp或win2003的系统栏右下角显示黄色的提示框 请问Windows Media Player 控件有无类似onplaying事件? 那为高人做过决策支持系统,有几个问题想问 在线等,100分,立结TListBox滚动问题! delphi 编写vxd驱动 上帝,救救我吧! 一个初学者的问题!! delphi5中有支持IMAP協議的控件嗎? 加分悬赏! 请教如何隐藏创建一个窗体。 delphi截游戏画面图
http://topic.csdn.net/u/20090423/08/0bab3642-4e07-423c-969e-d258006f1da0.html?seed=1323670561另外,你咋不贴代码呢,这么说,谁知道咋回事啊!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, myocxformProj1_TLB, StdVcl;type
Tmyocxform = class(TActiveForm, Imyocxform)
private
{ Private declarations }
FEvents: ImyocxformEvents;
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; public
{ Public declarations }
procedure Initialize; override;
procedure GetTest(a: Integer; out b: OleVariant); safecall;
end;implementationuses ComObj, ComServ;{$R *.DFM}{ Tmyocxform }procedure Tmyocxform.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
begin
{ Define property pages here. Property pages are defined by calling
DefinePropertyPage with the class id of the page. For example,
DefinePropertyPage(Class_myocxformPage); }
end;........procedure Tmyocxform.Set_ScreenSnap(Value: WordBool);
begin
ScreenSnap := Value;
end;procedure Tmyocxform.Set_SnapBuffer(Value: Integer);
begin
SnapBuffer := Value;
end;procedure Tmyocxform.Set_Visible(Value: WordBool);
begin
Visible := Value;
end;procedure Tmyocxform.GetTest(a: Integer; out b: OleVariant);
begin
b := a + random(10000);
end;initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
Tmyocxform,
Class_myocxform,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.此外,添加的方法都是procedure,可以加function函數嗎?
private
FOnActivate: TNotifyEvent;
FOnClick: TNotifyEvent;
FOnCreate: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnDestroy: TNotifyEvent;
FOnDeactivate: TNotifyEvent;
FOnKeyPress: TmyocxformOnKeyPress;
FOnPaint: TNotifyEvent;
FIntf: Imyocxform;
function GetControlInterface: Imyocxform;
protected
procedure CreateControl;
procedure InitControlData; override;
public
procedure GetTest(a: Integer; out b: OleVariant);//这是我加的方法
property ControlInterface: Imyocxform read GetControlInterface;
property DefaultInterface: Imyocxform 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;
2.找到svrip的get,set代码
自定义一个全局变量
var
sSvrIP:stringimplemention
....修改Set,get过程:
function ToLgn.Get_SvrIP: WideString;
begin
result:=sSvrIP;
end;procedure ToLgn.Set_SvrIP(const Value: WideString);
begin
sSvrIP:=Value;
end;注:不会自动生成变量处理代码,不自己写,将来使用Get_SvrIP根本收不到网页穿过来的变量值。
3.网页调用形式
<OBJECT
classid="clsid:CC721C00-9C4B-42DC-B3F6-4C78DDFD4A1E"
codebase="GetIP.ocx"
>
<param name="MyIP" value="192.168.0.3">
</OBJECT>
我要实现的功能是:
做个ocx控件,取IE客户端的机器MAC物理地址,然后回传给服务器,服务器根据这个MAC地址来判断该机器是否有权登录这个系统(用户要求指定某台机器才能使用系统)
再加50分,谢谢各位!!!