Delphi 2010 RTTI doesn't recognize array type

I'm using Delphi 2010 and trying to traverse simple structure by using RTTI. 
Does anybody know why RTTI cannot recognize array type and return nil instead of actual type?

Here is example:
type
  R = record
    f1: array [0 .. 0] of byte;
  end;

procedure Test;
var
  context: TRttiContext;
  field: TRttiField;
  rttiType: TRttiType;
begin
  context := TRttiContext.Create;

  rttiType := context.GetType(TypeInfo(R));
  for field in rttiType.GetFields do
    if field.FieldType = nil then
      Writeln('Type is nil.');
  context.Free;
end;
0
Andrey
10/21/2009 9:25:58 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

4 Replies
855 Views

Similar Articles

[PageSpeed] 38

Andrey Tihankov wrote:

> I'm using Delphi 2010 and trying to traverse simple structure by
> using RTTI.  Does anybody know why RTTI cannot recognize array type
> and return nil instead of actual type?
> 
> Here is example:
> type
>   R = record
>     f1: array [0 .. 0] of byte;
>   end;

If the type is nil, there was no need to have RTTI, IOW, the type is
blittable (which means the type does not need any special handling - it
can be copied around, cleared, etc. without any side effects) and you
only need SizeOf.
-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"And God said, 'Let there be light' and there was light, but the
 Electricity Board said He would have to wait until Thursday to be
 connected." -- Spike Milligan.
0
Rudy
10/21/2009 11:32:22 AM
<Andrey Tihankov> wrote in message news:175049@forums.codegear.com...
> I'm using Delphi 2010 and trying to traverse simple structure by using 
> RTTI.
> Does anybody know why RTTI cannot recognize array type and return nil 
> instead of actual type?
>

I'm not sure, guess there's no RTTI for it, but if you declare it like this 
it doesn't return nil:

type
  TmyArray = array[0..0] of byte;

  R = record
    f1: TmyArray;
  end;

I also can't seem to get any more useful info for static arrays just from 
the type, and need to query each instance (which I could understand for 
dynamic arrays, but seems a bit unnecesary for static ones):

var
  value: TValue;
  myRec: R;
....

value := field.GetValue(@myRec);
if value.IsArray then
begin
Writeln('Length = '+IntToStr(value.GetArrayLength);
// get each item with  "value.GetArrayElement(i)"...
end;
0
Daniel
10/21/2009 11:36:31 AM
> {quote:title=Daniel Bartlett wrote:}{quote}
> <Andrey Tihankov> wrote in message news:175049@forums.codegear.com...
> > I'm using Delphi 2010 and trying to traverse simple structure by using 
> > RTTI.
> > Does anybody know why RTTI cannot recognize array type and return nil 
> > instead of actual type?
> >
> 
> I'm not sure, guess there's no RTTI for it, but if you declare it like this 
> it doesn't return nil:
> 
> type
>   TmyArray = array[0..0] of byte;
> 
>   R = record
>     f1: TmyArray;
>   end;
> 
> I also can't seem to get any more useful info for static arrays just from 
> the type, and need to query each instance (which I could understand for 
> dynamic arrays, but seems a bit unnecesary for static ones):
> 
> var
>   value: TValue;
>   myRec: R;
> ...
> 
> value := field.GetValue(@myRec);
> if value.IsArray then
> begin
> Writeln('Length = '+IntToStr(value.GetArrayLength);
> // get each item with  "value.GetArrayElement(i)"...
> end;

Daniel,

Thank you for the useful workaround to declare array types separately. 
Some words about purpose of traversing static (plain) structures. I'm supporting huge application which is based on Btrieve. And these plain structures are the basis to access binary representation of Btrieve record. For each get/store operation we need to do encoding of string from Char to OEM (and vice versa). I thought RTTI could give me the way to distinguish array of chars from array of other types to do encoding automatically.
Unfortunately your second example doesn't work (it raises exception and doesn't return value) and seems no other way to figure out about field type for static arrays.

Andrey
0
Andrey
10/21/2009 9:07:49 PM
Andrey Tihankov wrote:

> I'm using Delphi 2010 and trying to traverse simple structure by
> using RTTI.  Does anybody know why RTTI cannot recognize array type
> and return nil instead of actual type?

This is a bug and has been reported as

Report No: 78560 (RAID: 273263)          Status: Open
Rtti information is insufficient for static array members of records.
http://qc.embarcadero.com/wc/qcmain.aspx?d=78560
-- 
Uwe
0
Uwe
10/21/2009 11:52:25 PM
Reply:

Similar Artilces:

Delphi 2010 can't upgrade Delphi 2007 projects
If I open any of my Delphi 2007 projects in Delphi 2010 it prompts me that it will upgrade it. Unfortunately, that leaves Delphi 2010 to give errors about not knowing where to find system and other core units. On the other hand, if I delete all the BDS project files and only leave the .dpr, Delphi 2010 can successfully open and compile my project. However, besides that quirk, I have another problem. I need to have both a working Delphi 2007 project and Delphi 2010, so I can compile using both without being prompted each and every time about upgrading project :) So... Any ideas to what m...

Delphi 2010 remote debugger version 2 doesn't stop at breakpoints
On a delphi 2010 installation fixed 4 and 5 updated ! I don't know what else to do. Loading process from local machine starts the application on remote machine and it seems that's working fine but ... when I select any breakpoint (*the circle has an "x" and colours green like when disabled...*) then program execution doesn't stop. I put the .rsm file on remote macchine but nothing nothing... any guru can help me ? regards Sorry but NOBODY uses remote debugger on Delphi 2010 o NOBODY has problems ??? thanks > {quote:title=Guillermo Ibanez wrote:}{qu...

Why doesn't Delphi do this?
Okay, so I'm anticipating Delphi 2009 getting myself back up to speed with language enhancements since Delphi 7 and came across this. I remember hearing about a feature to extend already defined types to add methods (class helpers), which is something I love about javascript (adding functionality to types that I expect). I want this, but it seems Delphi is limited (again). What I wanted to do was add the ability to say, add two TPoints together, and maybe multiple them by a matrix ... maybe even convert a TFloatingPoint into a TPoint. type TPointHelper = class helper for TPoint...

superreview granted: [Bug 122238] input type="image" doesn't send x/y (image doesn't exist; width and height not set) : [Attachment 139545] Same as jkeiser's patch, really...
Johnny Stenback <jst@mozilla.jstenback.com> has granted Boris Zbarsky <bz-vacation@mit.edu>'s request for superreview: Bug 122238: input type="image" doesn't send x/y (image doesn't exist; width and height not set) http://bugzilla.mozilla.org/show_bug.cgi?id=122238 Attachment 139545: Same as jkeiser's patch, really... http://bugzilla.mozilla.org/attachment.cgi?id=139545&action=edit ------- Additional Comments from Johnny Stenback <jst@mozilla.jstenback.com> + if (!name.IsEmpty()) { + aFormSubmission->AddNameValuePair(thi...

superreview requested: [Bug 122238] input type="image" doesn't send x/y (image doesn't exist; width and height not set) : [Attachment 139545] Same as jkeiser's patch, really...
Boris Zbarsky <bz-vacation@mit.edu> has asked Johnny Stenback <jst@mozilla.jstenback.com> for superreview: Bug 122238: input type="image" doesn't send x/y (image doesn't exist; width and height not set) http://bugzilla.mozilla.org/show_bug.cgi?id=122238 Attachment 139545: Same as jkeiser's patch, really... http://bugzilla.mozilla.org/attachment.cgi?id=139545&action=edit ...

Starting 2 TThread 's directly after each other doesn't work in delphi xe2 [Edit]
(SOLVED: iLog was not thread safe.) ----- Hello, I have a very simple thread: (note: iLog just logs output -- threadsafe; not included here.) {code} unit mySimpleThread; interface uses System.Classes, System.SysUtils, System.Types, System.UITypes, System.Variants; type TmySimpleThread = class(TThread) public constructor Create(); destructor Destroy; override; private procedure Execute; override; end; implementation constructor TmySimpleThread.Create(); begin inherited Create(True); iLog('TmySimpleThread created'); end...

Delphi 2009 doesn't start any more
I worked with Delphi 2009 for some weeks without any problem. Today the program crashes with an access violation at address 0042A6B4, Read/Write of address 0400911A - no splash screen or other activities are to be seen, the program fails to start right away. Pressing OK makes bds.exe disappear from the task manager. I finally gave up trying to understand what happened and installed Delphi 2009 completely new. Now it starts again and seems to work properly. The question is for how long ... .... not too long. After I installed, as recommended, update package 3 the program failed to start aga...

Delphi 6 to Delphi XE2: can't find required package.
We have a Delphi 6 Project Group that we like to work on in Delphi XE2. When trying to build the project, we get the DCC Fatal Error E2202: Required package 'cds' not found. With Delphi 6 we've used the following tools: - JVCL340 & JCL221 - devExpress QuantumGrid 6 - QuickReport (default in Delphi 6) - Visoco Sybase Driver, Devart Oracle en MSSQL drivers With Delphi XE2 (update 3 installed) we're using the following tools and settings for now (after removing Delphi 6 in an attempt to make it work) : - JVCL345 & JCL231 (http://jvcl.delphi-jedi.org/) - devExpr...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

from delphi 6 to delphi 2010
Hi. It is possible, with component RX, dxforumlibrary, InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. Thank by comments. excequiel arostica wrote: >Hi. > It is possible, with component RX, dxforumlibrary, >InfoPower3000Pro, StringAlignGrid. Accepts communication BDE. > >Thank by comments. Rx is dead and sources are taken over by jcl/jvcl. I dont know about the rest of the components and i have no experiences with bde over the last 9 years. excequiel arostica wrote: > Hi. > It is possible, with component RX, dxforumlibrary,...

how to set array length with delphi 2010 rtti [Edit]
how to set array length in runtime ? setLength(t.GetProperty('Propertys'),3); ???? {code:delphi} unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TSubProperty = Class private Fitem2: Integer; Fitem1: String; procedure Setitem1(const Value: String); procedure Setitem2(const Value: Integer); published property item1:String read Fitem1 write Setitem1; property item2:Integer read Fitem2 write Setitem2;...

Can't find TComponentEditor in Delphi 2010
Hello, I'm moving from Delphi 2006 to 2010. I've a component that used DesignIntf and DesignEditors. I understand that these are not used in 2010 but that 'Requires' has to have 'designide.dcp'. (I searched for this - ...\RAD Studio\7.0\lib to avoid typos!) I've done this, but it can't find TComponentEditor - ie, 'E2003 undeclared identifier'. I'd appreciate any guidance here. Thanks, Ian Ian Johnson wrote: > Hello, I'm moving from Delphi 2006 to 2010. I've a component that > used DesignIntf and DesignEditors. I understa...

Delphi XE debugger doesn't work
I have installed Delphi XE on Win 7 Prof. If I use the Start Button to execute an application the debugger doesn't notice any breakpoints. If I start an application via the windows explorer and connect the debugger to the process, in some cases debugging is posible. Does anybody have an idea? Thanks. Did you noticed that there are two startbuttons.. One green and another green with red bug.. Keyboard keys: With debugging = F9 Without debugging = Shift-Ctrl-F9 That was the clue. Sometimes you don't see the forest because of all the trees (german saying). Thank you ...

Can't install DecisionCube on Delphi 2010
DecisionCube is announced from embarcadero as an extra for Delphi 2010, but it cannot be compiled !! So why do they provide it as an extra ?? google knows what embarcadero isn't willing to tell us?? http://www.allottware.co.za/Blog/archive/2009/12/03/how-to-get-decision-cubes-to-work-with-ado-in.aspx i didn't follow this advice, but it seems to work well, perhaps i try that later. I started this adventure with decisioncube here: http://cc.embarcadero.com/item/27351 and yes, i have Delphi 2010 Pro !! "John Landmesser" <jmlandmesser@gmx.de> schrieb ...

Web resources about - Delphi 2010 RTTI doesn't recognize array type - embarcadero.delphi.general

Resources last updated: 11/26/2015 4:45:30 AM