Hello
I am trying to capture when the user enters a new value in a cell check that it is a valid entry, and if not the cell should remain focused prompting the user to enter another value. I noticed that the onCellChanged event seems to handle this functionality well. But I am trying to determine the data type i.e. is it a numeric value or a string value and do different tests based on the datatype. The value has not been set when onCellChanged is called there for I cannot test as follows
if profgrid.cells[Acol, Arow].Value > 10 then
so I had a look at the onCellExit, which can check the value of the cell accurately but it is hard to get back to the right cell and populate it with the original value if the change is not a valid one.
Any suggestions on how to check the value of a cell prior to it's being changed and check if it is valid. I need to know the datatype of the cell
procedure TMarkbookEntryForm.StringGrid1CellExit(Sender: TProfGrid; ACol,
ARow: Integer);
var
typeString : string;
basicType : Integer;
begin
StringListIsDirty := True;
FileSave.Enabled := True;
// Get the Variant basic type :
// this means excluding array or indirection modifiers
basicType := VarType(StringGrid1.Cells[ACol, ARow].Value) and VarTypeMask;
// Set a string to match the type
case basicType of
varEmpty : typeString := 'varEmpty';
varNull : typeString := 'varNull';
varSmallInt : typeString := 'varSmallInt';
varInteger : typeString := 'varInteger';
varSingle : typeString := 'varSingle';
varDouble : begin
if StringGrid1.Cells[ACol, ARow].Value > StrToInt(StringGrid1.Cells[StringGrid1.Col, 1].Value) then
begin
beep;
StringGrid1.Cells[ACol, ARow].Value := LastChangedValue;
StringGrid1.FocusCell(Acol, ARow-1);
end;
end;
varCurrency : typeString := 'varCurrency';
varDate : typeString := 'varDate';
varOleStr : typeString := 'varOleStr';
varDispatch : typeString := 'varDispatch';
varError : typeString := 'varError';
varBoolean : typeString := 'varBoolean';
varVariant : typeString := 'varVariant';
varUnknown : typeString := 'varUnknown';
varByte : typeString := 'varByte';
varWord : typeString := 'varWord';
varLongWord : typeString := 'varLongWord';
varInt64 : typeString := 'varInt64';
varStrArg : typeString := 'varStrArg';
varString : typeString := 'varString';
varAny : typeString := 'varAny';
varTypeMask : typeString := 'varTypeMask';
end;
// Show the Variant type
ShowMessage('Variant type is '+typeString);
end;
Thanks for any advice
Jake