Posts

Showing posts with the label generics

Database field to Generic T conversion?

Database field to Generic T conversion? What is the cleanest and/or fastest way to convert a variant to a specific type T where T is limited to a simple type and comes from a database.  uses   rtti, Data.Db; type   TMyClass = class      function Convert(const Field: TField):T;   end; How slow will using RTTI be?  function TMyClass .Convert(const const Field: TField):T; var   v: TValue; begin   v := TValue.FromVariant(Field.AsVariant);   Result := V.AsType ; end; Am I better off using explicit conversions and/or casts per TFieldType or per Variant type?  Just to explain why I want to do this: End goal is to have a non-visual "virtual query result grid" (i.e. rows by columns) where values are converted from database values to their "natural" Delphi types and then passed to other systems which will render the data with various decorators. Grid sizes can in theory vary from 10 rows by 20 columns to 5000 rows by 60 columns.  I want to let go of the Dataset as fast as po...