怎样使用DELPHI开发的ACTIVEX控件得到通过URL中传递过来的参数?(200分)

  • 主题发起人 主题发起人 lu_ning
  • 开始时间 开始时间
L

lu_ning

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用DELPHI做一个ActiveX FORM,在调用这个包含ActiveX的页面时,我希望通过URL把
参数传递给ActiveX FORM。请问各位高手我该怎么做?谢谢!
 
获取HTML参数需要实现 IPersistPropertyBag 接口
...
TActiveTest = class(TActiveForm, IActiveTest, IPersistPropertyBag)
// 加入IPersistPropertyBag接口
...
private
...
{ IPersistPropertyBag }
function IPersistPropertyBag.InitNew = PersistPropertyBagInitNew;
function IPersistPropertyBag.Load = PersistPropertyBagLoad;
function IPersistPropertyBag.Save = PersistPropertyBagSave;
function PersistPropertyBagLoad(const pPropBag: IPropertyBag
const pErrorLog: IErrorLog): HResult
stdcall;
function PersistPropertyBagSave(const pPropBag: IPropertyBag
fClearDirty: BOOL
fSaveAllProperties: BOOL): HResult
stdcall;
function PersistPropertyBagInitNew: HResult
stdcall;
function GetClassID(out classID: TCLSID): HResult
stdcall;
...
implementation
...
function TActiveTest.GetClassID(out classID: TCLSID): HResult;
begin
Result := S_OK;
end;

function TActiveTest.PersistPropertyBagInitNew: HResult;
begin
Result := S_OK;
end;

function TActiveTest.PersistPropertyBagSave(const pPropBag: IPropertyBag;
fClearDirty, fSaveAllProperties: BOOL): HResult;
begin
Result := S_OK;
end;

function TActiveTest.PersistPropertyBagLoad(const pPropBag: IPropertyBag;
const pErrorLog: IErrorLog): HResult;
var
v: OleVariant;
begin
if pPropBag.Read( 'name', v, pErrorLog) = S_OK then
ShowMessage('Get name parameter is ' + v);

Result := S_OK;
end;
// 读入HTML name参数,并显示
....


HTML 如下所示

<HTML>
<H1> Delphi 6 ActiveX Test Page </H1><p>
You should see your Delphi 6 forms or controls embedded in the form below.
<HR><center><P>
<OBJECT
classid="clsid:AF10804E-A44A-4174-AD09-B23892AE39FD"
codebase="http://DragonPC/cgi-bin/ActiveTestProj1.ocx#version=1,0,0,0"
width=314
height=74
align=center
hspace=0
vspace=0
>
<PARAM name="name" value="[come on baby, get name parameter]">
</OBJECT>
</HTML>
 
搞定,其实只是获取了Browser的IWebBrowser2接口而已,所以要use SHDocVw,

procedure TActiveTest.Button1Click(Sender: TObject);
var
// Site: IOleClientSite;
// OleObj: IOleObject;
// OleCont: IOleContainer;
browser: IWebBrowser2;
isp: IServiceProvider;
begin
// ShowMessage('Dragon P.C. Test ActiveX Form');
// if (IUnknown(Self).QueryInterface(IOleObject, OleObj) = S_OK) and
// begin
// if (Site.GetContainer(OleCont) = S_OK) then
// begin
//
// end;
// end;
isp := ActiveFormControl.ClientSite as IServiceProvider;
if (isp.QueryService(IWebbrowserApp, IWebbrowser2, browser) = S_OK) then
begin
ShowMessage('Browser URL is := ' + browser.LocationURL);
end;
end;
 
谢谢!谢谢!太谢谢了!
 
后退
顶部