我建立了一个form,然后在form中建立了一个自己定义的函数SaveForm101ToStruct101();
在函数中有如下代码:
var
run_time:Integer;
begin
run_time := lbl_runtime_0.Width; //lbl_runtime_0是一个Label;
end;
提示是:lbl_runtime_0.Widt访问错误。
请问怎么解决?谢谢各位!!!!
在函数中有如下代码:
var
run_time:Integer;
begin
run_time := lbl_runtime_0.Width; //lbl_runtime_0是一个Label;
end;
提示是:lbl_runtime_0.Widt访问错误。
请问怎么解决?谢谢各位!!!!
run_time := form1.lbl_runtime_0.Width;
run_time := your_form.lbl_runtime_0.Width;
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的成员函数了。
编译没有问题。
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;
我估计是调用的地方,在不恰当的时候调用了SaveForm101ToStruct101方法
例如在form正在构建的时候(formcreate事件里),这时候访问form上任何控件都是出错的,原因是他们还没出生呢