关于在函数里面调用控件问题!

seven_diligent 2009-05-05 11:20:46
function getUrlSource(strUrl: string):string; //获取网页源码
begin

//try
lsResult := IdHTTP1.GET(strUrl);

//except
//ShowMessage('获取源码出错');
//end;

end;


错误提示:IdHTTP1没定义!页面上已加入TIdHTTP控件。
...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bdmh 2009-05-05
  • 打赏
  • 举报
回复
楼主的getUrlSource,看样子不是TForm的成员函数,当访问窗体组件时,需要指明组件的所属

或者

把getUrlSource作为TForm的成员函数,那样就可以了
haitao 2009-05-05
  • 打赏
  • 举报
回复
form1的方法才能这样使用
独立函数,需要指明控件是那个form里的
hongqi162 2009-05-05
  • 打赏
  • 举报
回复
隐含的self指针问题
bdmh 2009-05-05
  • 打赏
  • 举报
回复
from1.IdHTTP1,指明所属
lhy 2009-05-05
  • 打赏
  • 举报
回复
也许名字不叫“IdHTTP1”;
也许你没有uses含有IdHTTP1的unit
hongqi162 2009-05-05
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
function getUrlSource(strUrl: string):string;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.getUrlSource(strUrl: string): string;
begin
//try
lsResult := IdHTTP1.GET(strUrl);

//except
//ShowMessage('获取源码出错');
//end;
end;

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧