可以在StringGrid的SetEditText事件中加以判断 procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); begin if (ARow Mod 2 = 0) then begin if StrToIntDef(Value, 0) < 0 then ShowMessage('请输入正数'); end else begin if StrToIntDef(Value, 0) > 0 then ShowMessage('请输入负数'); end; end;
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); begin if (ARow Mod 2 = 0) then begin if StrToIntDef(Value, 0) < 0 then ShowMessage('请输入正数'); end else begin if StrToIntDef(Value, 0) > 0 then ShowMessage('请输入负数'); end; end;楼上正解。
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
begin
if (ARow Mod 2 = 0) then begin
if StrToIntDef(Value, 0) < 0 then
ShowMessage('请输入正数');
end
else begin
if StrToIntDef(Value, 0) > 0 then
ShowMessage('请输入负数');
end;
end;
ARow: Integer; const Value: String);
begin
if (ARow Mod 2 = 0) then begin
if StrToIntDef(Value, 0) < 0 then
ShowMessage('请输入正数');
end
else begin
if StrToIntDef(Value, 0) > 0 then
ShowMessage('请输入负数');
end;
end;楼上正解。