unit nine;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
var Count:Integer;{$R *.dfm}Function NoValue(AnEditBox:TEdit):Boolean;
begin
if AnEditBox.Text='' then
begin
Label1.Color:=clRed; //出错信息undeclared identifier 'Label'
Label1.Caption:= '请输入两个数字'; //出错信息missing operator or semicolon;
Result:=True;
end
else
begin
Label1.Color:=clWindow; //出错信息missing operator or semicolon
Result:=False;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var x,y:Integer;
begin
if NoValue(Edit1) or NoValue(Edit2) then
exit;
Count:=Count+1;
Button1.Caption:=IntToStr(Count);
x:=StrToInt(Edit1.Text);
y:=StrToInt(Edit2.Text);
Edit3.Text:=IntToStr(x+y);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
end;initialization
Count := 0;end.
要怎么改才能让NoValue函数里能访问到Label1,才能让程序正确执行?谢谢啦!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
var Count:Integer;{$R *.dfm}Function NoValue(AnEditBox:TEdit):Boolean;
begin
if AnEditBox.Text='' then
begin
Label1.Color:=clRed; //出错信息undeclared identifier 'Label'
Label1.Caption:= '请输入两个数字'; //出错信息missing operator or semicolon;
Result:=True;
end
else
begin
Label1.Color:=clWindow; //出错信息missing operator or semicolon
Result:=False;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var x,y:Integer;
begin
if NoValue(Edit1) or NoValue(Edit2) then
exit;
Count:=Count+1;
Button1.Caption:=IntToStr(Count);
x:=StrToInt(Edit1.Text);
y:=StrToInt(Edit2.Text);
Edit3.Text:=IntToStr(x+y);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
end;initialization
Count := 0;end.
要怎么改才能让NoValue函数里能访问到Label1,才能让程序正确执行?谢谢啦!
这句改成
Form1.Label1.Color := clRed;
其它一样改就可以!