function GetAllWebLinks(szWebAddress: string): TStrings;
function GetAllWebLinks(szWebAddress: string; depth: integer): TStrings; overload; //Depth 为网站搜索深度(递归深度)。 函数返回用的TStrings变量如何释放内存?
function GetAllWebLinks(szWebAddress: string; depth: integer): TStrings; overload; //Depth 为网站搜索深度(递归深度)。 函数返回用的TStrings变量如何释放内存?
解决方案 »
- 这两种方法返回的句柄不一样,那里出问题了?
- delphi读取txt时候的中文乱码
- termb.dll内存错误,二代身份证识别的问题,请指正
- 新手问题:access2000设置别名的问题
- 我想用sql server实现动态排序,排序结果在DELPHI的stringgrid中显示,可以吗?
- 初学者问题?
- 关于在DELPHI中调用CAD并保存结果的问题
- 我现在有个问题请教,如果成功我会给分的,急急急
- 大侠帮忙, 一个字符串怎么样才能转换成一个字节数组? 我是菜鸟只有22分了
- 怎么让下拉式菜单里面出现图标呀?
- ==就这么点分数了:关于Oracle,Delphi,安装制作的问题?(高手请进)===
- 帮我看看这段代码,问题出在什么地方。谢谢
free的问题楼主问过的吧,你可以这样做:
astringlist:=getallweblinks();
使用astringlist;
astringlist.free;
这样使用前不经create,astringlist其实是你的函数中创建的。
主 题: 我按照《程序员大本营2001 Borland版》第68页做的《使用Internet Explor在Web 页面中查找所有的链接》程序无法运行!(Win98+IE5.5+Delphi5)出现以下错误提示:Project FindingLinks.exe...
//----------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, OleCtrls, SHDocVw;type
TForm1 = class(TForm)
wb1: TWebBrowser;
Panel1: TPanel;
Edit1: TEdit;
Memo1: TMemo;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementationuses MSHTML;{$R *.DFM}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (Edit1.Text <> '') and (Key = #13) then
wb1.Navigate(Edit1.Text);
end;procedure TForm1.wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
Doc:IHTMLDocument2;
ElementCollection:IHTMLElementCollection;
HTMLElement:IHTMLElement;
I:Integer;
AnchorString:string;
begin
Memo1.Clear;
Doc:=wb1.Document as IHTMLDocument2;
If Doc = nil then
raise Exception.Create('不能转化为 IHTMLDocument2');
ElementCollection:=doc.all;
for I:=0 to ElementCollection.length-1 do
begin
HTMLElement:=ElementCollection.item(I,'') as IHTMLElement;
if HTMLElement.tagName ='A' then
begin
{AnchorString:= HTMLElement.innerText;
if AnchorString='' then
AnchorString:='(Empty Name)';
AnchorString:=AnchorString+'-'+(HTMLElement as IHTMLAnchorElement).href;
Memo1.Lines.Add(AnchorString);}
Memo1.Lines.Add((HTMLElement as IHTMLAnchorElement).href);
end;
end;
end;end.
var
i: Integer;
begin
for i := 0 to Webbrowser1.OleObject.Document.links.Length - 1 do
Listbox1.Items.Add(Webbrowser1.OleObject.Document.Links.Item(i));
end; 对于多个Frame的页面,可以采取下面的代码:
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
Listbox1.Clear;
//if frames available
if Webbrowser1.OleObject.Document.Frames.Length <> 0 then
begin
//walk through all frames and get the url
//to the Listbox
for i := 0 to Webbrowser1.OleObject.Document.Frames.Length - 1 do
begin
Listbox1.Items.Add(Webbrowser1.OleObject.Document.Frames.item(i).Document.URL);
end;
end;
end;