此段程序运行正常,Label1.Caption被改写
procedure TForm1.Button1Click(Sender: TObject);
begin
    Label1.Caption :=inet1.OpenURL('http://localhost/vb/1.asp');
end;
此段程序运行错误
Function connentURL(URL1:String):String
var
  Inet1: TInet;
  Label1: TLabel;
begin
  Label1.Caption :=Inet1.OpenURL('http://localhost/vb/1.asp');
end;Inet1、Label1已在interface中声明,不过不再在自定义函数中声明的话,系统将提示“未定义”。此段程序的系统错误提示信息如下:
Debugger Exception Notification
---------------------------
Project DataTransfer.exe raised exception class EAccessViolation with message 'Access violation at address 00462114 in module '×××.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.这是什么原因呢?

解决方案 »

  1.   

    Function connentURL(URL1:String):String
    var
      Inet1: TInet;
      Label1: TLabel;
    begin
      Form1.Label1.Caption :=Inet1.OpenURL('http://localhost/vb/1.asp');
    end;//前面加個 Form1.
      

  2.   

    因為上一個, 是包含了在類 TForm中的, 運行時會直接引用自己
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        Label1.Caption :=inet1.OpenURL('http://localhost/vb/1.asp');
    end;
    也相當于
      self.Label1.Caption :=inet1.OpenURL('http://localhost/vb/1.asp');
    而這裹的 self 就是 TForm1 的實例了!
      

  3.   

    to:aiirii(ari-爱的眼睛)
       Form1.Label1.Caption :=Form1.Inet1.OpenURL('http://localhost/vb/1.asp');就OK了
       谢谢你,大版主!
       还想问一下,如果要把自定义函数变成窗体的方法,应该怎么做呀?
      

  4.   

    声明到窗口的类当中即可了type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure ss;
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.ss;
    begin
    end;
      

  5.   

    如果你把函数Function connentURL(URL1:String):String
    放到你的那个类的private或者public
    就不会出问题了
      

  6.   

    谢谢大家,为什么不能正常给分呢?奇怪ing……