Steps to reproduce:
-new firemonkey-application
-add TCheckBox to form
Now create a method with following code:
procedure TForm1.Foo;
var a,b:Integer; lVal:TValue;
begin
lVal:=TValue.From<Integer>(42);
a:=lVal.AsInteger;
checkbox1.Data:=TValue.From<Integer>(42);
b:=checkbox1.Data.AsInteger;
end;
The cast with lVal runs without problems, checkbox1.data however, even if it's a TValue too, throws an "EInvalidCast"-Error, when calling AsInteger. The same error appears when using checkbox1.data.AsType<Integer> instead.
Am I misusing TCheckBox.Data here or is this some kind of bug?
TCheckBox.Datacontainsbooleanvalue, specifically check box checked state. That is why you getEInvalidCasterror when you try to readIntegerfrom it.The reason why you seemingly can put
Integerdata in, is becauseTCheckBox.SetDatawill just ignore invalid data types and setsDatatoFalse.