Delphi FMX TIntegerColumn SetValue: Invalid Typecast

  

I have an FMX TGrid with a checkbox column, a string column and an integer column. I’ve managed to make the string column and checkbox columns work. But when I change the integer column, the TValue passed to the SetValue command does not seem to be passing an integer.

I’ve set up a string column (StrNumber) to do what I want, but if I try to handle the value from the IntegerColumn I get a ClassCastException. I’ve tried the various number types as well Value.AsBoolean, Value.AsString, etc. but I always get Invalid Typecast.

procedure MyApp.SuppGridSetValue(Sender: TObject; const ACol, ARow: Integer; const Value: TValue);
begin
if SuppGrid.Columns[ACol] = StrNumber then
Caption := IntToStr(StrToIntDef(Value.AsString,1));
else if SuppGrid.Columns[ACol] = Number then
Value.AsInteger; //see note
end;

NOTE: In the code above “Value.AsInteger” wouldn’t get used even if it did work but this demonstrates clearly that the issue isn’t some other call creating the ClassCastException.

When debugging the inspection window doesn’t offer much either. It does appear that the value is coming in as all 0s or nils, no matter what I try to set it as.

(FData:(FTypeInfo:$4012BC; FValueData:TValueDataImpl($B7D78E8) as IValueData; FAsUByte:0; FAsUWord:0; FAsULong:0; FAsObject:nil; FAsClass:nil; FAsSByte:0; FAsSWord:0; FAsSLong:0; FAsSingle:0; FAsDouble:0; FAsExtended:0; FAsComp:0; FAsCurr:0; FAsUInt64:0; FAsSInt64:0; FAsMethod:(Code:nil; Data:nil); FAsPointer:nil))

That is, I’ve tried (in the GetValue) setting a direct simple value:

Value := 42;

Also using a From call:

Value := TValue.From<Integer>(42); //doesn’t work for an integer column

In these cases the value “42” shows up in the right column, but the value passed to the SetValue routine does not seem to have either the original value of 42, or the user’s data.

Comments are closed.