S
shang_yan
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我自己软件中的一段代码,目的是将数组参数从客户端程序传到Com程序里,可老是不成功。大家帮我看看客户端的代码存在着什么问题?
//客户端:我用以下代码不能将数组传到Com端程序
procedure TComClient.btn1Click(Sender: TObject);
var
doc: IHTMLdocument2;
AUrl: string;
Links: IHTMLElementCollection;
i: integer;
Element: IHTMLElement;
App: Variant;
UrlList: OleVariant;
begin
try
doc := IHTMLdocument2(IE.Document);//这里是为了得到IHtmlDocument2,可以成功地得到
Links := doc.Get_links;
try
UrlList := VarArrayCreate([0, Links.length], varVariant);
except
showmessage('Dll 错误1');
end;
for i := 0 to links.length - 1 do
begin
Element := (Links.Item(i, 0) as IHTMLElement);
if assigned(Element) then
begin
UrlList := Element.getAttribute('href', 0);
AUrl := AUrl + UrlList + chr(13);
end;
end;
showmessage(chr(13) + aurl);//我加这句是为了看代码是否运行到了这里
App := CreateOleObject('webpic.Getpic');
// App.GetWebUrl(doc.url);//这句能够正常地将string类型的变量传过去
app.GetAllImage(UrlList);//运行到这里,com端程序可以成功启动,但urlList数组没有传过去,这也正是我需要解决的问题
except showmessage('dll 错误2');
end;
end;
//服务端,这段代码应该是没有问题的。因为我通过VBScript代码创建了TComServer,并成功地将一个数组传了进来。
procedure TComServer.GetAllImage(url: variant);
var
i: integer;
FPicType, FromUrl: string;
AListItem: TListItem;
begin
if fromUrl = 'about:blank' then exit;
frmGetInPage.LVUrl.Items.Clear;
frmGetInPage.FromUrl := Url[0];
//frmGetInPage.txtProjTitle.Text := Url[0];
for i := 1 to VarArrayHighBound(url, 1) do
begin
FPicType := UpperCase(ExtractfileExt(Url));
if (Lowercase(FPicType) = '.jpg')
or (Lowercase(FPicType) = '.gif')
or (Lowercase(FPicType) = '.png')
or (Lowercase(FPicType) = '.ico')
or (Lowercase(FPicType) = '.bmp') then
begin
AListItem := frmGetInPage.LVUrl.Items.Add;
AListItem.Caption := StripAllStr(FPicType, '.');
AListItem.SubItems.Add(Url);
AListItem.Checked := True;
AListItem.Update;
end; //end if lowercase
end; //end for
frmGetInPage.show;
end;
//客户端:我用以下代码不能将数组传到Com端程序
procedure TComClient.btn1Click(Sender: TObject);
var
doc: IHTMLdocument2;
AUrl: string;
Links: IHTMLElementCollection;
i: integer;
Element: IHTMLElement;
App: Variant;
UrlList: OleVariant;
begin
try
doc := IHTMLdocument2(IE.Document);//这里是为了得到IHtmlDocument2,可以成功地得到
Links := doc.Get_links;
try
UrlList := VarArrayCreate([0, Links.length], varVariant);
except
showmessage('Dll 错误1');
end;
for i := 0 to links.length - 1 do
begin
Element := (Links.Item(i, 0) as IHTMLElement);
if assigned(Element) then
begin
UrlList := Element.getAttribute('href', 0);
AUrl := AUrl + UrlList + chr(13);
end;
end;
showmessage(chr(13) + aurl);//我加这句是为了看代码是否运行到了这里
App := CreateOleObject('webpic.Getpic');
// App.GetWebUrl(doc.url);//这句能够正常地将string类型的变量传过去
app.GetAllImage(UrlList);//运行到这里,com端程序可以成功启动,但urlList数组没有传过去,这也正是我需要解决的问题
except showmessage('dll 错误2');
end;
end;
//服务端,这段代码应该是没有问题的。因为我通过VBScript代码创建了TComServer,并成功地将一个数组传了进来。
procedure TComServer.GetAllImage(url: variant);
var
i: integer;
FPicType, FromUrl: string;
AListItem: TListItem;
begin
if fromUrl = 'about:blank' then exit;
frmGetInPage.LVUrl.Items.Clear;
frmGetInPage.FromUrl := Url[0];
//frmGetInPage.txtProjTitle.Text := Url[0];
for i := 1 to VarArrayHighBound(url, 1) do
begin
FPicType := UpperCase(ExtractfileExt(Url));
if (Lowercase(FPicType) = '.jpg')
or (Lowercase(FPicType) = '.gif')
or (Lowercase(FPicType) = '.png')
or (Lowercase(FPicType) = '.ico')
or (Lowercase(FPicType) = '.bmp') then
begin
AListItem := frmGetInPage.LVUrl.Items.Add;
AListItem.Caption := StripAllStr(FPicType, '.');
AListItem.SubItems.Add(Url);
AListItem.Checked := True;
AListItem.Update;
end; //end if lowercase
end; //end for
frmGetInPage.show;
end;