我建立了一个form,然后在form中建立了一个自己定义的函数SaveForm101ToStruct101();
    在函数中有如下代码:
    var
    run_time:Integer;
    begin
       run_time := lbl_runtime_0.Width; //lbl_runtime_0是一个Label;
    end;
    提示是:lbl_runtime_0.Widt访问错误。
    请问怎么解决?谢谢各位!!!! 
    

解决方案 »

  1.   

    你的自定义函数不是Form的成员函数。把函数定义到窗体结构里面,或者
    run_time := form1.lbl_runtime_0.Width;
      

  2.   

    maybe your function SaveForm101ToStruct101() is not the member method of your form, so you should use the member of your form in the function as following:
    run_time := your_form.lbl_runtime_0.Width;
      

  3.   

    申明
    procedure Timer1Timer(Sender: TObject);
        procedure FormActivate(Sender: TObject);
      private
        { Private declarations }
        time_i, time_j, stoptime_second, runtime_second : Integer;
      public
        { Public declarations }
        procedure SaveForm101ToStruct101();//////////////////////////////////////
    procedure Tfrm_101.SaveForm101ToStruct101();
    begin
    end;我是这样申明和定义的。应该是把它定义为Form的成员函数了。
    编译没有问题。
      

  4.   

    lbl_runtime_0是个什么玩意,哪里来的,代码就不能贴全一点吗。
      

  5.   

    type
      Tfrm_101 = class(TForm)
        Image_bk: TImage;
        lbl_runtime_0: TLabel;    Timer1: TTimer;
        procedure FormShow(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormActivate(Sender: TObject);
      private
        { Private declarations }
        time_i, time_j, stoptime_second, runtime_second : Integer;
      public
        { Public declarations }
        procedure SaveForm101ToStruct101();
    procedure Tfrm_101.SaveForm101ToStruct101();
    var
        run_time:Integer;
    begin
        run_time := lbl_runtime_0.Width;
    end;
      

  6.   

    代码中看不出错误,楼主是在什么方法中调用SaveForm101ToStruct101的?
      

  7.   

    run_time := Form1.lbl_runtime_0.Width
      

  8.   

    贴出错提示出来看看
    我估计是调用的地方,在不恰当的时候调用了SaveForm101ToStruct101方法
    例如在form正在构建的时候(formcreate事件里),这时候访问form上任何控件都是出错的,原因是他们还没出生呢