dmitrybv 3 Posted August 20 Are there methods in the TValue class or in Rtti to convert a string to the desired simple type (Like Integer, Float, DateTime)? TValue has a method that converts a simple value to a string - TValue.ToString, but there is no reverse method TValue.FromString. I tried using StrValue.Cast<Integer>(); but this method throws 'Invalid class typecast' exception. procedure TFormSimpleDraw2.Button3Click(Sender: TObject); var StrValue: TValue; IntValue: TValue; Str: String; begin IntValue := 10; StrValue := IntValue.ToString(); // IntValue := TValue.FromString(Str); IntValue := StrValue.Cast<Integer>(); end; Share this post Link to post
Der schöne Günther 316 Posted August 20 (edited) TValue is designed to hold any type, not just "simple" ones. There is no way to marshal a string representation like "(record)" or "(interface @ 02549BD0)" back into what they once were. Maybe what you are looking for is a mechanism to serialize any record/object in memory into a string (or raw bytes), store them, and later de-serialize them? Edited August 20 by Der schöne Günther Share this post Link to post
Stefan Glienke 2009 Posted August 20 Convert<T> from TValueHelper in Spring. See https://bitbucket.org/sglienke/spring4d/src/2.0.1/Source/Base/Spring.pas#lines-651 1 Share this post Link to post