delphi中StringGrid.Cells如果没有输入数字,怎么显示一个提醒的窗口???
unitUnit11;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,...
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells [0,1] := ' 小明';
StringGrid1.Cells [0,2] := ' 小红';
StringGrid1.Cells [1,0] := ' 语文';
StringGrid1.Cells [2,0] := ' 数学';
StringGrid1.Cells [3,0] := ' 英语';
StringGrid1.Cells [4,0] := ' 合计';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
result1,result2 ,i : integer;
begin
result1 := 0;
for i:=1 to 3 do
begin
result1:= result1 + strtoint(stringgrid1.Cells [i,1]);
if ( stringgrid1.Cells [i,1] = '' ) then
begin
button1.Enabled := false;
messagebox ( handle,'没有数字!' , 'error',mb_ok );
break;
end
else
continue ;
end;
StringGrid1.Cells [4,1] := inttostr(result1) ;
result2 := 0;
for i:=1 to 3 do
begin
result2:= result2 + strtoint(stringgrid1.Cells [i,2]);
end;
StringGrid1.Cells [4,2] := inttostr(result2) ;
end;
end. 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells [0,1] := ' 小明';
StringGrid1.Cells [0,2] := ' 小红';
StringGrid1.Cells [1,0] := ' 语文';
StringGrid1.Cells [2,0] := ' 数学';
StringGrid1.Cells [3,0] := ' 英语';
StringGrid1.Cells [4,0] := ' 合计';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
result1,result2 ,i : integer;
begin
result1 := 0;
for i:=1 to 3 do
begin
result1:= result1 + strtoint(stringgrid1.Cells [i,1]);
if ( stringgrid1.Cells [i,1] = '' ) then
begin
button1.Enabled := false;
messagebox ( handle,'没有数字!' , 'error',mb_ok );
break;
end
else
continue ;
end;
StringGrid1.Cells [4,1] := inttostr(result1) ;
result2 := 0;
for i:=1 to 3 do
begin
result2:= result2 + strtoint(stringgrid1.Cells [i,2]);
end;
StringGrid1.Cells [4,2] := inttostr(result2) ;
end;
end. 展开
展开全部
楼上正解 , 简单方法 先判断 是否为空 不是空的再加,
procedure TForm1.Button1Click(Sender: TObject);
var
result1,result2 ,i : integer;
begin
result1 := 0;
for i:=1 to 3 do
begin
if ( stringgrid1.Cells [i,1] = '' ) then
begin
button1.Enabled := false;
messagebox (Form1.Handle,'没有数字!' , 'error',mb_ok );
break;
end
else
result1:= result1 + strtoint(stringgrid1.Cells [i,1]);
end;
if i=4 then StringGrid1.Cells [4,1] := inttostr(result1) ;
result2 := 0;
for i:=1 to 3 do
begin
if ( stringgrid1.Cells [i,2] = '' ) then
begin
button1.Enabled := false;
messagebox (Form1.Handle,'没有数字!' , 'error',mb_ok );
break;
end
else
result2:= result2 + strtoint(stringgrid1.Cells [i,2]);
end;
if i=4 then StringGrid1.Cells [4,2] := inttostr(result2) ;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询