Recent

Author Topic: mORMot/AsTSQLRecord doesn't work with lazarus  (Read 245 times)

matrix1233

  • Newbie
  • Posts: 1
mORMot/AsTSQLRecord doesn't work with lazarus
« on: November 30, 2020, 07:51:02 am »
Hi,
I have a problem with mormot and Lazarus, so XX.AsTSQLRecord it work perfectly on Delphi but when i try to use the same code on lazarus i have this message : Error: Incompatible types: got "Pointer" expected "TNoteCase". I used a simple code that i have copied from https://tamingthemormot.wordpress.com/tag/mormot/ .
So can you help me to resolve this problem ? Thanks
Code: Pascal  [Select][+][-]
  1. unit NoteORM;
  2. interface
  3.  
  4. uses Classes, SynCommons, mORMot;
  5.  
  6. type
  7.   TNoteCase = class(TSQLRecord)
  8.   private
  9.     FDescription: RawUTF8;
  10.   published
  11.     property Description: RawUTF8 read FDescription write FDescription;
  12.   end;
  13.  
  14.   TNote = class(TSQLRecord)
  15.   private
  16.     FBody: RawUTF8;
  17.     FTitle: RawUTF8;
  18.     FNoteCase: TNoteCase;
  19.   published
  20.     property NoteCase: TNoteCase read FNoteCase write FNoteCase;
  21.     property Body: RawUTF8 read FBody write FBody;
  22.     property Title: RawUTF8 index 80 read FTitle write FTitle;
  23.   end;
  24.  
  25. implementation
  26.  
  27. end.  
  28.  
/
Code: Pascal  [Select][+][-]
  1.        
  2. var
  3.   Form1: TForm1;
  4.   Database: TSQLRest;
  5.   Model: TSQLModel;
  6.  
  7. implementation
  8.  
  9. {$R *.lfm}
  10. procedure Tform1.TestIt(rest:TSQLRest);
  11. var
  12.   aCase : NoteORM.TNoteCase;
  13.   aNote : NoteORM.TNote;
  14. begin
  15.   aCase := NoteORM.TNoteCase.Create;
  16.   try
  17.     aCase.Description := 'Case 1';
  18.     rest.Add( aCase, true );
  19.     aNote := NoteORM.TNote.Create;
  20.     try
  21.       aNote.Title := 'Note 1';
  22.       aNote.Body  := 'Note 1 body. Lots of other stuff too.';
  23.       aNote.NoteCase := aCase.AsTSQLRecord ;   // here  it's work with delphi but doesn't work with lazarus
  24.       rest.Add( aNote, true );
  25.  
  26.       aNote.Title := 'Note 2';
  27.       aNote.Body  := 'Note 2 body. Lots of other stuff too. Some more things here.';
  28.       rest.Add( aNote, true );
  29.     finally
  30.       aNote.Free;
  31.     end;
  32.   finally
  33.     aCase.Free;
  34.   end;
  35. end;
  36.  
  37. procedure TForm1.Button1Click(Sender: TObject);
  38. begin
  39.    Model    := TSQLModel.Create([TNoteCase,TNote]);
  40.    Database := TSQLRestServerDB.Create(Model,ChangeFileExt(paramstr(0),'.db3'));
  41.    TSQLRestServerDB(Database).CreateMissingTables;
  42.    TestIt(Database);
  43. end;
  44.  
  45.  
/         
« Last Edit: November 30, 2020, 07:53:12 am by matrix1233 »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1388
Re: mORMot/AsTSQLRecord doesn't work with lazarus
« Reply #1 on: November 30, 2020, 08:42:20 am »
I guess you need to set FPC into Delphi mode.
Add:
{$MODE DELPHI}

You could also add:
{$I Synopse.inc}

OkobaPatino

  • Full Member
  • ***
  • Posts: 191
Re: mORMot/AsTSQLRecord doesn't work with lazarus
« Reply #2 on: November 30, 2020, 08:44:59 am »
It will help if you cast it to TNoteCas as you are probably are running your code in mode objfpc. Try adding {$mode delphi} after the unit name; this way, you probably will not need a cast.
What DonAlfredo said is the best practice, especially if you want to keep compatibility with Delphi.

 

TinyPortal © 2005-2018