我有
uses
System.Rtti;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
_UserString: string;
_CastedValue: TValue;
_IntExampleValue: TValue;
_DateTimeExampleValue: TValue;
begin
_UserString := '55';
_IntExampleValue := TValue.From<integer>(-199);
if not TValue.From(_UserString).TryCast(_IntExampleValue.TypeInfo, _CastedValue)
then
ShowMessage('Failed to cast')
else
ShowMessage('Casted successfully');
_UserString := DateTimeToStr(Now);
_DateTimeExampleValue := TValue.From<TDateTime>(Now);
if not TValue.From(_UserString).TryCast(_DateTimeExampleValue.TypeInfo, _CastedValue)
then
ShowMessage('Failed to cast')
else
ShowMessage('Casted successfully');
end;
两次我都收到消息说它无法投射,但为什么呢?我看不出有什么不对。