写成函数,就找不到控件了(10分)

  • 主题发起人 主题发起人 angel725
  • 开始时间 开始时间
A

angel725

Unregistered / Unconfirmed
GUEST, unregistred user!
unit GG;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
IdHTTP1: TIdHTTP;
procedure Timer1Timer(Sender: TObject);

private
{ Private declarations }

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation


{$R *.dfm}
function zhonghang():string;
begin

with TStringList.Create do try
Text := IdHTTP1.Get('http://www.xxx.com');
if Count > 2 then
begin
edit1.Text:= Copy(Strings[Count - 2], 0, 8);
edit2.Text:= Copy(Strings[Count - 2], 0, 8);
end;
finally
Free;
end;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
zhonghang();
end;

end.
错误:
[Error] GGold.pas(47): Undeclared identifier: 'IdHTTP1'
[Error] GGold.pas(50): Undeclared identifier: 'edit1'
[Error] GGold.pas(51): Undeclared identifier: 'edit2'


这段不对了??
找不到控件,
函数放错位置了?
 
加个申明看看
 
如下就可以了。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls, StdCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
IdHTTP1: TIdHTTP;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
function zhonghang():string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
zhonghang();
end;

function TForm1.zhonghang: string;
begin
with TStringList.Create do try
Text := IdHTTP1.Get('http://www.xxx.com');
if Count > 2 then
begin
edit1.Text:= Copy(Strings[Count - 2], 0, 8);
edit2.Text:= Copy(Strings[Count - 2], 0, 8);
end;
finally
Free;
end;
end;

end.
 
1:function zhonghang():string;
-->function TForm1.zhonghang():string;
or
2:Text := IdHTTP1.Get('http://www.xxx.com');
-->Text := Form1.IdHTTP1.Get('http://www.xxx.com');
 
接受答案了.
 
后退
顶部