I'm using this code to get the element type of an array
{$APPTYPE CONSOLE}    
uses
  Rtti,
  SysUtils;
type
  TFooArray= array  of TDateTime;
Var
  T : TRttiType;
begin
  try
     T:=TRttiContext.Create.GetType(TypeInfo(TFooArray));
      Writeln(TRttiArrayType(T).ElementType.Name);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
but the application fails with an access violation on this line
Writeln(TRttiArrayType(T).ElementType.Name);
How I can get the element type of an array using the RTTI?
You cast is wrong the TRttiArrayType is for static arrays (and your array is dynamic), to fix the issue use the TRttiDynamicArrayType instead like so : 
 Writeln(TRttiDynamicArrayType(T).ElementType.Name);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With