我有个自定义过程是这样的:procedure test;
begin
  label1.caption:='hi';
end;运行报错,一定要这样才能通过:procedure test;
begin
  from1.label1.caption:='hi';
end; 请问如何声明该过程可以用第一种方法。另问一句,这2个过程有什么利弊,比如内存占用等。

解决方案 »

  1.   

    procedure test; 放到from1的成员函数中
      

  2.   

    unit test;
    interface
    uses
      windows;
    type
      TForm1=class(TForm)
      procedure test;<------------------A
      private
      procedure test;<------------------B
      public
      procedure test;<------------------C
    end;在ABC哪个位置?
      

  3.   

    我放在A位置,报错!unit test;
    interface
    uses
      windows;
    type
      TForm1=class(TForm)
        procedure test;<------------------A
      private  publicend;
      

  4.   

    将procedure test;放在private 下在 test前加 TForm1:
    procedure TForm1.test;
    begin
      label1.caption:='hi';
    end;
      

  5.   

    你的问题呢,第一个是因为你定义的过程是在TForm1类之外的,所以你要用TForm1的成员时,你就需要指明TForm1的实例名称。像Form1.XXX的。
    第二个你定义的过程作为了TForm1的成员函数,你必须定义在protected,private,public这些关键字之下。所以你不能写在你所谓的A的位置。