"JetCar.Netscape" 对象的 AddUrlList 方法(200分)

  • 主题发起人 主题发起人 黄忠伟
  • 开始时间 开始时间

黄忠伟

Unregistered / Unconfirmed
GUEST, unregistred user!
下载软件flashget 在ie浏览器的右键集成了一个菜单“使用网际快车下载所有链接”,
我想通过写代码把我需要的下载地址传给 flashget 。
在flashget的路径中有一个jc_all.htm文件,内容是这样的:
<script language="VBScript">
'Great thanks to Vladimir Romanov(Author of ReGet Pro)
On Error Resume Next
set JetCarCatch=CreateObject("JetCar.Netscape")
if err<>0 then
MsgBox("FlashGet not properly installed!"+ vbCrLf+"Please Install FlashGet again")
else
set links = external.menuArguments.document.links
ReDim params(links.length*2)
params(0)=external.menuArguments.document.Url
for i = 0 to links.length-1
params(i*2+1)=links(i).href
params(i*2+2)=links(i).innerText
next
JetCarCatch.AddUrlList params
end if
</script>

它实际上就是调用了 "JetCar.Netscape" 对象的 AddUrlList 方法,
我用delphi写了如下代码:

procedure TForm1.Button1Click(Sender: TObject);
var
myObject:Variant;
paraStr,test:array[0..1] of string
//把 string 改成 Variant,出错原因还是一样

begin
myObject:=CreateOleObject('JetCar.Netscape');
paraStr[0]:= 'http://www.guilin.com.cn/caiwuke/room.exe';
paraStr[1]:='room';
myObject.AddUrlList(paraStr)
//这句代码出错
end;
  
结果语法检查时出错: Type not allowed in Variant Dispatch call

请问我应该怎么写?谢谢
 
procedure TForm1.Button1Click(Sender: TObject);
var
myObject:Variant;
paraStr,test:array[0..1] of string[255];
OtherParam: OleVariant;
begin
myObject:=CreateOleObject('JetCar.Netscape');
paraStr[0]:= 'http://www.guilin.com.cn/caiwuke/room.exe';
paraStr[1]:='room';
OtherParam := VarArrayCreate([0, 1], varOleStr);//或是 varString, 我没测试
OtherParam[0] := paraStr[0];
OtherParam[1] := paraStr[1];
myObject.AddUrlList(OtherParam);
end;
 
procedure TForm1.Button2Click(Sender: TObject);
var
FGObj: Variant;
rgsabound: array[0..1] of SAFEARRAYBOUND;
psa: PSafeArray;
ppsa: ^PSafeArray;
ele: OleVariant;
ix: LongInt;
vList: VARIANT;
begin
FGObj := CreateOleObject('JetCar.Netscape');

rgsabound[0].lLbound := 0;
rgsabound[0].cElements := 5;
psa := SafeArrayCreate(VT_VARIANT, 1, rgsabound);
ppsa := @psa;
if (psa = nil) then exit;

ix := 0;
//ele.SetString('http://www.amazesoft.com', VT_BSTR);
ele := WideString('http://www.amazesoft.com');
SafeArrayPutElement(psa, ix, ele);

inc(ix);
//ele.SetString('http://www.amazesoft.com/fgf076.zip', VT_BSTR);
ele := WideString('http://www.amazesoft.com/fgf076.zip');
SafeArrayPutElement(psa, ix, ele);

inc(ix);
ele := WideString('FlashGet 0.76');
SafeArrayPutElement(psa, ix, ele);

inc(ix);
ele := WideString('http://www.amazesoft.com/doc.zip');
SafeArrayPutElement(psa, ix, ele);

inc(ix);
ele := WideString('FlashGet Documentation');
SafeArrayPutElement(psa, ix, ele);

TVarData(vList).VType := VT_VARIANT or VT_ARRAY or VT_BYREF;

TVarData(vList).VArray := @psa;

FGObj.AddUrlList(vList);
SafeArrayDestroy(psa);
end;
 
MilkRoad:
不知道你测试这段代码没有,同样的代码在FlashGet给出的VC例子中没有问题,但是在Delphi7中调试时会出现错误(不影响结果),在程序单独运行时出现“Invalid argument.”的错误(同样也不影响结果),不知所以,很不爽。
另外为何一定要用SafeArray这种方法,能帮忙解释一下吗?
 

Similar threads

后退
顶部