有没有办法将网格中单元格的内容与变量的内容进行比较。
我需要比较单元格 0,1,如果它的值低于(或高于)变量 x,那么就会发生一些事情。
我正在使用 Lazarus 和 StringGrid。
有没有办法将网格中单元格的内容与变量的内容进行比较。
我需要比较单元格 0,1,如果它的值低于(或高于)变量 x,那么就会发生一些事情。
我正在使用 Lazarus 和 StringGrid。
您可以尝试这样的事情(对于整数值,但可以很容易地修改为其他序数类型)。你也可以关注commented version
这篇文章:
uses
Math;
function CompareValueEx(StringGrid: TStringGrid; const Column, Row: Integer;
const Value: Integer; out Relationship: TValueRelationship): Boolean;
var
Output: Integer;
begin
Result := TryStrToInt(StringGrid.Cells[Column, Row], Output);
if Result then
Relationship := CompareValue(Value, Output);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Relationship: TValueRelationship;
begin
I := 111;
StringGrid1.Cells[1, 2] := '112';
if CompareValueEx(StringGrid1, 1, 2, I, Relationship) then
begin
case Relationship of
EqualsValue: ShowMessage('The values are the same');
LessThanValue: ShowMessage('The I value is less than in cell [1;2]');
GreaterThanValue: ShowMessage('The I value is greater than in cell [1;2]');
end;
end
else
ShowMessage('The value in cell [1;2] is not a valid integer value!');
end;