Persistent crash in RTTI unit

I purchased Aurelius and Data Modeler last week then wasted my whole weekend trying to get it to work on my system. I was able to get the demos to work, but when I included one of my own table mappings, generated by Data Modeler, the system would crash with an access violation in the FindCtor procedure in RTTI.pas.  If I cut and pasted this class into a simple, standalone application, all seemed to work well. I spent two whole days trying just about every option to get around this error - enabling and disabling RTTI in the project settings, moving attributes around on the class, compiling with and without debug included, optimizations on and off, debug DCU's, looking for {$RTTI... options in my code and all third party libraries, everything I could think of - nothing worked.

Today I come into work and install Aurelius and data Modeler here. I downloaded the source code from the weekend to my office system, and with no other changes to the code, the app worked - saving and loading records from the database. The only difference between this and my home system is that I'm behind a firewall and can't run the automatic setup - the Aurelius files were copied from my home system and installed manually.

Then my XE bogged down, which it does on occasion. The cure is to delete all dcu files from my project dcu directory - rebuild the project and poof - same error as yesterday - I'm back to square one.  Now nothing I do will allow me to use Aurelius.

I'm running Delphi XE and the latest version of Aurelius, downloaded on Saturday. The error occurs whenever I try to do something with the manager - Find, Save, etc.  The system crashes with an AV  at the following line in the RTTI.pas unit. It looks like it's trying to scan the attributes at this point.

function FindCtor(AttrType: TRttiInstanceType; CtorAddr: Pointer): TRttiMethod;
  type
    PPPointer = ^PPointer;
  var
    p: PByte;
    imp: Pointer;
  begin
    for Result in AttrType.GetMethods do
      if Result.CodeAddress = CtorAddr then
        Exit;
    // expect a package (i.e. DLL) import
    p := CtorAddr;
    Assert(p^ = $FF); // $FF $25 => indirect jump m32
    Inc(p);
    Assert(p^ = $25);
    Inc(p);
    imp := PPPointer(p)^^;                                              << Crash occurs here
    for Result in attrType.GetMethods do
      if Result.CodeAddress = imp then
        Exit;
    Result := nil;
  end;

Is this a configuration issue, a Delphi bug or an Aurelius bug? Any help would be appreciated before I give up on using Aurelius - it's just costing me too much time.

Looks like a Delphi issue: http://stackoverflow.com/questions/9499135/error-while-trying-to-access-class-attributes. Or at least, a bad error message.

From a guess without seeing your code, looks like some problem in the uses clause, maybe you have classes with same name in different units? Like Aurelius attributes, nullable types, etc.? What are the units in your uses clause, in the unit where you declare the class?

In the unit that defines the class, pretty much just Aurelius units with one Delphi unit. These are all in the interface section, nothing in the implementation section.

uses
  Generics.Collections,
  Aurelius.Mapping.MappedClasses,
  Aurelius.Mapping.Setup,
  Aurelius.Mapping.Explorer,
  Aurelius.Drivers.Interfaces,
  Aurelius.Engine.DatabaseManager,
  Aurelius.Engine.ObjectManager,
  Aurelius.Sql.Firebird,
  Aurelius.Mapping.Metadata,
  Aurelius.Mapping.Attributes,
  Aurelius.Types.Nullable;

The class itself is defined thus:

type
   TSAMPLES_SAMPLING = class;

  [Entity]
  [Table('SAMPLES_SAMPLING')]
  [Id('FASN', TIdGenerator.None)]
  TSAMPLES_SAMPLING = class
  private
    [Column('ASN', [])]
    FASN: integer;

    [Column('SAMPLE_APPEARANCE', [], 40)]
    FSAMPLE_APPEARANCE: Nullable<string>;

    [Column('SAMPLING_METHOD', [])]
    FSAMPLING_METHOD: Nullable<integer>;

    [Column('SAMPLING_COMPANY', [], 25)]
    FSAMPLING_COMPANY: Nullable<string>;

    [Column('COLECTOR_COMMENTS', [], 40)]
    FCOLECTOR_COMMENTS: Nullable<string>;

    [Column('DEPTH_TOP', [])]
    FDEPTH_TOP: Nullable<double>;

    [Column('DEPTH_MIDDLE', [])]
    FDEPTH_MIDDLE: Nullable<double>;

    [Column('DEPTH_BOTTOM', [])]
    FDEPTH_BOTTOM: Nullable<double>;

    [Column('DEPTH_UNITS', [], 6)]
    FDEPTH_UNITS: Nullable<string>;

    [Column('GROUND_ELEV', [])]
    FGROUND_ELEV: Nullable<double>;

    [Column('WELL_ELEV', [])]
    FWELL_ELEV: Nullable<double>;

    [Column('LATITUDE', [])]
    FLATITUDE: Nullable<double>;

    [Column('LONGITUDE', [])]
    FLONGITUDE: Nullable<double>;

    [Column('SAMPLE_TYPE', [], 30)]
    FSAMPLE_TYPE: Nullable<string>;

    [Column('FIELD_FILTERED', [])]
    FFIELD_FILTERED: Nullable<integer>;

    [Column('SITE_ID', [], 25)]
    FSITE_ID: Nullable<string>;

    [Column('MONITORING_POINT_ID', [], 25)]
    FMONITORING_POINT_ID: Nullable<string>;
  public
    property ASN: integer read FASN write FASN;
    property SAMPLE_APPEARANCE: Nullable<string> read FSAMPLE_APPEARANCE write FSAMPLE_APPEARANCE;
    property SAMPLING_METHOD: Nullable<integer> read FSAMPLING_METHOD write FSAMPLING_METHOD;
    property SAMPLING_COMPANY: Nullable<string> read FSAMPLING_COMPANY write FSAMPLING_COMPANY;
    property COLECTOR_COMMENTS: Nullable<string> read FCOLECTOR_COMMENTS write FCOLECTOR_COMMENTS;
    property DEPTH_TOP: Nullable<double> read FDEPTH_TOP write FDEPTH_TOP;
    property DEPTH_MIDDLE: Nullable<double> read FDEPTH_MIDDLE write FDEPTH_MIDDLE;
    property DEPTH_BOTTOM: Nullable<double> read FDEPTH_BOTTOM write FDEPTH_BOTTOM;
    property DEPTH_UNITS: Nullable<string> read FDEPTH_UNITS write FDEPTH_UNITS;
    property GROUND_ELEV: Nullable<double> read FGROUND_ELEV write FGROUND_ELEV;
    property WELL_ELEV: Nullable<double> read FWELL_ELEV write FWELL_ELEV;
    property LATITUDE: Nullable<double> read FLATITUDE write FLATITUDE;
    property LONGITUDE: Nullable<double> read FLONGITUDE write FLONGITUDE;
    property SAMPLE_TYPE: Nullable<string> read FSAMPLE_TYPE write FSAMPLE_TYPE;
    property FIELD_FILTERED: Nullable<integer> read FFIELD_FILTERED write FFIELD_FILTERED;
    property SITE_ID: Nullable<string> read FSITE_ID write FSITE_ID;
    property MONITORING_POINT_ID: Nullable<string> read FMONITORING_POINT_ID write FMONITORING_POINT_ID;
  end;

No other class with the same name in any other unit.

OK, I may have found the solution although still not sure if this will be a permanent fix. To get around the bug in Delphi XE where error insight flags false errors, I include the units for all third party libraries in my project file. This also has the side effect that the units are pulled in and compiled into my projects dcu directory. When I removed the Aurelius files from my project, and changed the library path to point to the compiled Aurelius units only, the error vanished.So it looks like as long as I don't recompile the Aurelius units along with my application, I may be good to go.

From what I've seen so far, I think this is going to revolutionize my app development - can't wait to start playing with the features now!

Thanks for the feedback, Dave. I hope you enjoy Aurelius!