Invalid pointer

Hi!

I have a problem creating a working TObjectManager.

I create it run-time

  FConnection := Connection;

//  FDbConnection := TZeosLibConnectionAdapter.Create(FConnection, false); //This was my first aproach

  FAureliusConnection := TAureliusConnection.Create(self);
  FAureliusConnection.SQLDialect := 'MySQL';
  FAureliusConnection.AdapterName := 'ZeosLib';
  FAureliusConnection.AdaptedConnection := FConnection;

  FDbConnection := FAureliusConnection.CreateConnection;

  FDbManager := TDatabaseManager.Create(FDbConnection);
  FManager := TObjectManager.Create(FDbConnection);

  TMappingExplorer.Default.Events.OnSqlExecuting.Subscribe(
    procedure(Args: TSQLExecutingArgs)
    begin
      Logger.Log(llSql, Args.SQL);
    end
  );

when executing this code

Result := FManager.Find<TReportTemplate>(TemplateId);

I get the error (MadExcept):

date/time          : 2021-10-20, 13:19:34, 599ms
computer name      : ZIPPOWKS
user name          : marko
registered owner   : marko / Hewlett-Packard
operating system   : Windows 10 x64 build 19043
system language    : Slovenian
system up time     : 15 hours 12 minutes
program up time    : 3 minutes 15 seconds
processors         : 4x Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
physical memory    : 5214/16260 MB (free/total)
free disk space    : (C:) 10,87 GB
display mode       : 3440x1440, 32 bit
process id         : $45f8
allocated memory   : 236,91 MB
largest free block : 699,82 MB
executable         : Easy.exe
exec. date/time    : 2021-10-20 13:15
version            : 2021.10.19.3
compiled with      : Delphi 10.4 Sydney
madExcept version  : 5.1.0
callstack crc      : $a592549d, $2940eee2, $6a9a0031
exception number   : 1
exception class    : EAccessViolation
exception message  : Access violation at address 018F9F8A in module 'Easy.exe'. Read of address 00000004.

thread $3c8:
018f9f8a +0da Easy.exe     Aurelius.Commands.AbstractCommandPerformer   179 +16 TAbstractCommandPerformer.SetEntityType
0198342f +04b Easy.exe     Aurelius.Engine.ObjectManager                 88  +5 TCommandPerformerFactory.GetCommandMeta<Aurelius.Commands.Selecter.TSelecter>
01983478 +018 Easy.exe     Aurelius.Engine.ObjectManager                 78  +1 TCommandPerformerFactory.GetCommandMeta<Aurelius.Commands.Selecter.TSelecter>
0197eaac +028 Easy.exe     Aurelius.Engine.ObjectManager               2576  +3 TObjectManager.TEngineCursor.CheckSelecter
0197ec01 +021 Easy.exe     Aurelius.Engine.ObjectManager               2613  +1 TObjectManager.TEngineCursor.Next
0190a3a8 +040 Easy.exe     Aurelius.Criteria.Base                      1065  +3 TCriteria.FillList
0197aa0b +083 Easy.exe     Aurelius.Engine.ObjectManager               1288 +12 TObjectManager.Find
01b2d850 +018 Easy.exe     PrintMngr                                   1337  +1 TObjectManager.Find<Template.TReportTemplate>
01b2d41e +036 Easy.exe     PrintMngr                                     95  +2 TPrintManager.GetTemplate
01c2f40c +124 Easy.exe     Searcher                                     299 +14 TfrmSearcher.UseItem
01cebb17 +0c3 Easy.exe     DatasetsModule                              2310 +14 TmodMain.SearchTemplate
01ce50bb +0d7 Easy.exe     DatasetsModule                               917  +9 TmodMain.PrintDocument
01ce4fbd +045 Easy.exe     DatasetsModule                               892 +10 TmodMain.PrintDocument
01fd4a51 +069 Easy.exe     ViewDocuments                               2095  +4 TfrmDocuments.actPrintDocExecute
00561763 +00f Easy.exe     System.Classes                             17671  +3 TBasicAction.Execute
005f6b5a +086 Easy.exe     Vcl.ActnList                                 284 +19 TCustomAction.Execute
005615b7 +013 Easy.exe     System.Classes                             17582  +2 TBasicActionLink.Execute
00731da7 +093 Easy.exe     Vcl.Menus                                   2603 +17 TMenuItem.Click
0073357f +013 Easy.exe     Vcl.Menus                                   3562  +5 TMenu.DispatchCommand
007347fa +082 Easy.exe     Vcl.Menus                                   4735  +4 TPopupList.WndProc
00734749 +01d Easy.exe     Vcl.Menus                                   4710  +2 TPopupList.MainWndProc
005624b8 +014 Easy.exe     System.Classes                             18175  +8 StdWndProc
753e7f5b +00b user32.dll                                                        DispatchMessageW
0074f1d7 +0f3 Easy.exe     Vcl.Forms                                  11028 +23 TApplication.ProcessMessage
0074f21a +00a Easy.exe     Vcl.Forms                                  11058  +1 TApplication.HandleMessage
0074f551 +0c9 Easy.exe     Vcl.Forms                                  11196 +26 TApplication.Run
021aff2d +051 Easy.exe     Easy                                         313  +6 initialization
7569fa27 +017 KERNEL32.DLL                                                      BaseThreadInitThunk

What am I doing wrong?

class code (i double checked the table and columns names)

  [Entity]
  [Table('type_template')]
  TReportTemplate = class
  private
    [Column('ID')]
    FId: integer;
    [Column('DOC_TYPE')]
    FReportId: integer;
    [Column('NAME')]
    FDisplayName: string;
    [Column('DESCRIPTION')]
    FDescription: string;
    [Column('DIRECT_PRINT')]
    FDirectPrint: boolean;
    [Column('FILENAME')]
    FFileName: string;
    [Column('LAST_CHANGED')]
    FLastChanged: TDateTime;

    procedure SetFilename(const Value: string);
    function UpdateFileName(AFileName: string): string;
  public
    property Id: integer read FId write FId;
    property ReportId: integer read FReportId write FReportId;
    property DisplayName: string read FDisplayName write FDisplayName;
    property Description: string read FDescription write FDescription;
    property DirectPrint: boolean read FDirectPrint write FDirectPrint;
    property FileName: string read FFileName write SetFilename;
    property LastChanged: TDateTime read FLastChanged write FLastChanged;
  end;

You have not mapped the [Id] of the class. Please add the [Id] attribute. We will improve the error message in this case.

It's aaaaliiiiveee!!!!

Thank you!

P.S.: Yes, a clearer error description should help a lot :)

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.