#1 Re: mORMot 2 » Can not make replication to work » 2023-11-06 12:32:59

I have another version written for Lazarus if that could be easier for someone to checkout.
https://gitlab.com/GIT-Testing/mormot-r … th-lazarus

This version works as bad as any other of my attempts to find a working solution.

Looks that it is not possible to have the real-time sync with this library.

#2 Re: mORMot 2 » Can not make replication to work » 2023-11-02 10:59:32

Please see my updated reply above.

It seems that it only works once after that I erase the user table first and then start the slave.
The data is copied from master to the slave just after the call:

fSlave.RecordVersionSynchronizeSlaveStart(TOrmUser, fMasterClient, nil);

But not after.

Very strange or...?

#3 Re: mORMot 2 » DynArrayLoadJson can not process the JSON with "a", "A" names data? » 2023-10-22 08:15:03

There is an error in the json structure
      "c": "28403.81000000",
      "a": "28420.61000000",
      "A": "0.00351000", <--- THIS COMMA is not valid here.

You can use this link: https://jsonlint.com/
Best regards

#4 Re: mORMot 2 » Can not make replication to work » 2023-10-21 09:44:53

Hello ab,
I've already checked out that code and I did a new attempt with a small testproject but still fail.
I have this project available as a zip-file but I don't find any way to share that. PasteBin doesn't seem to to be used with anything but sourcefiles.
Any idea how I can share this file?

I have the project on GITLAB if it could work?
https://gitlab.com/GIT-Testing/test_mor … cation.git

I made a small program that more or less copies the code you have in your test suite.


That code works but the difference is that I don't use services here. When simulating changes in the master table I do it directly through the TRestServerDB instance.

But in the real world I need to use services and then I need 2 different http-channels, one for update the table on the master and one for the replication.
And this case don't work for me. See the the GITLAB-project above.
I'm sure that I have misunderstood how to do this correct but I'm also sure it must be someone, that have a working solution of a similar system like mine, that could see what I've done wrong or..?

Otherwise I have to develop a compleatly different solution on my own :-(
Please help.

#5 Re: mORMot 2 » Can not make replication to work » 2023-10-13 11:14:35

No answer in a week, I hoped to find some anwer here at least a comment if some necessary information is missing.
I tried to find a solution myself and I feel that I've done what is needed but in spit of that, no success.
I don't believe that this function is incomplete or not functional in mORMot2 but it looks so to me. sad

#6 mORMot 2 » Can not make replication to work » 2023-10-05 10:04:15

Replies: 6

Only when the master server is restarted the sync works but only once.

In the slave log I can see the following repeated five times:

2023-10-05 09:24:14.640	Debug	    mormot.rest.sqlite3.TRestServerDB(035da1e0) RecordVersionSynchronizeSlaveStart(TORMUser) current=19 Subscribe(036ec488)
2023-10-05 09:24:14.640	Enter	    mormot.soa.client.TServiceFactoryClient(036fac98).InternalInvoke IServiceRecordVersion.Subscribe("User",19,1) 
2023-10-05 09:24:14.640	Enter	       mormot.rest.http.client.TRestHttpClientWebsockets(03d93730).InternalUri POST
2023-10-05 09:24:14.640	Trace	          mormot.rest.http.client.TRestHttpClientWebsockets(03d93730) InternalRequest POST calling THttpClientWebSockets(03d939a0).Request
2023-10-05 09:24:14.640	Client	          mormot.rest.http.client.TRestHttpClientWebsockets(03d93730) POST DHSSync/ServiceRecordVersion.Subscribe status=200 len=18 state=1
2023-10-05 09:24:14.640	Leave	       00.003.082
2023-10-05 09:24:14.640	Service return	       mormot.soa.client.TServiceFactoryClient(036fac98) {"result":[false]}

and then  I get an error:

2023-10-05 09:24:14.704	Error	    mormot.rest.sqlite3.TRestServerDB(035da1e0) RecordVersionSynchronizeSlaveStart(TORMUser): retry failure 

The code in the slave looks like this:

procedure TForm5.btnSynchronizeClick(Sender: TObject);
  function setUpSyncServer: TRestServerDB;
    result := TSQLRestServerDB.Create(CreateSyncModel, ChangeFileExt(Executable.ProgramFileName, '.db'));
    result.DB.Synchronous := smOff;
    result.DB.LockingMode := lmNormal;

  if not fSyncRunning then
    btnSynchronize.Caption := 'Stopp Synk';
    fSyncServer := SetUpSyncServer;
    fHttpClientSync := TRestHttpClientWebSockets.Create('', '8888', CreateSyncModel);

    fSyncServer.RecordVersionSynchronizeSlaveStart(TORMUser, fHttpClientSync);
    fSyncRunning := true;
    btnSynchronize.Caption := 'Synka';
    fSyncRunning := false;


The master part:

function setUpOrmSyncServer: TRestServerDB;
  result := TRestServerDB.Create(CreateSyncModel, ChangeFileExt(Executable.ProgramFileName, '.db'));
  result.DB.LockingMode := lmNormal;

  OrmSyncServer := setUpOrmSyncServer;
  HttpSyncServer := TRestHttpServer.Create('8888', [OrmSyncServer], '+', UseBidirSocket,4 );

So I just wonder, What am I missing?

#7 Re: mORMot 2 » Examples on how to find an object in a dynamic array » 2023-07-28 14:10:23

Ok, I've done that already but as the array can contain several hundreds of object in the worst case I thought that using a dynamic array could be more effective.
In this case, load and response time is not an issue but I like to be more effective and I can think of cases where this could be an issue.
And why not to be prepared?

#8 mORMot 2 » Examples on how to find an object in a dynamic array » 2023-07-28 09:36:50

Replies: 3

I have a class that contains an array where I need to find a certain object in this array as I want to update this certain object.

I've tried to find examples of how to do this but still failed so my hope is that someone could have such an example to show how this could be done.

Thanks in advance!

#9 mORMot 2 » IRestOrm.add don't report duplicate error » 2023-05-26 07:11:00

Replies: 2

I would like to inform the client when trying to add an already existing record.
But the exception from sqlite3 is not forwarded. The call IRestOrm.add just return zero and the exception can only be seen in the server log.

How could I solve this?

#10 Re: mORMot 2 » Problem adding object to an ObjArray in a service. » 2023-05-12 09:08:12

Thanks Thomas, excelent solution even though it didn't help eliminate the invalid pointer operation.

Thanks ab, your comment woke me up, I asked myself why I use the whole objects in the parameter list when I only need the ID:s.
So I replaced those parameters with the id:s of the objects and now everything is alright again. smile

#11 mORMot 2 » Problem adding object to an ObjArray in a service. » 2023-05-11 20:56:10

Replies: 3

I have two classes TArticle and TSubProject. A SubProject can contain several articles.
Articles can be added by demand to the subproject.

I'm using "ObjArrayAdd" to add new articles to the subproject.
Like: ObjArrayAdd(aSubP.Articles, aArticle);

But that's not allowed - I get this message from delphi: "Constant object can not be passed as var parameter"

So I tried to use an intermediate variable and that calms delphi but executing the program gives me another error:
"Invalid pointer operation" when the function exits. But the database is updated then.

I' understand that I do something really wrong but how should I do?

The repository:

function TDHSSyncRepository.addArticleToSubProject(var aSubP: TSubProject;
  out aArticle: TArticle): TSyncRepoError;
  s: TArticleObjArray;
  if RetrieveArticle(aArticle) <> srSuccess then begin
    result := srNotFound;
  Result := srNotFound;
 // ---                         --> ObjArrayAdd(aSubP.Articles, aArticle); <<--- "Constant object can not be passed as var parameter
  s := aSubP.Articles;         //  <<---- Do this instead
  ObjArrayAdd(s, aArticle);  // << -- Works but gives "Invalid operation"
  aSubP.Articles := s;         //

Best regards,

#12 Re: mORMot 2 » At client startup - Interface not found fInterfaces.FindHashed(aUri) » 2023-05-09 12:26:22

Oh, I got your answer while I was writing.

Yea, I can see now!

Maybe I was not completely wrong about the parameter..?
I took the code from an example just to get a kickstart for testing.
I should be more careful.

Thank's a lot!

#13 Re: mORMot 2 » At client startup - Interface not found fInterfaces.FindHashed(aUri) » 2023-05-09 12:05:29

Sorry, I found the problem. It's of course my mistake. I misunderstood the usage of the parameter "ContractExpected". It looks like it should have the same name as the service without the leading 'T'. I got the impression of that this parameter is used to make it possible of same version control of the interface. So if you add a new or changed a method you could change this parameter and in that way you get a signal if you have different versions between client and server.

Strange is that I'm sure I had a different name for this parameter from the beginning without any problem.

Sorry I bothered you with this.
Best regards

#14 Re: mORMot 2 » At client startup - Interface not found fInterfaces.FindHashed(aUri) » 2023-05-09 10:51:41

To make a simple test client I added the following code:

procedure TForm4.FormCreate(Sender: TObject);
  Model := TOrmModel.Create([],SYSTEMLocalROOT);
  HttpClient := TRestHttpClient.Create(IP_Local, HTTP_PORT, Model);
  HttpClient.ServiceDefine([IDHSLocalService], sicShared, DHS_LOCAL_CONTRACT);

In the function "TServiceContainerClientAbstract" the parameter aInterfaces contains one interface "IDHSLocalService" which is correct here. I' only use one interface so far.

The call "fHash.FindOrNew(fHash.HashOne(@Item), @Item, nil);" with Item as 'DHS_LOCAL_CONTRACT' returns -161.
This lead to that he interface pointer will be nil.
I'm not sure how to reproduce with a RawUTF8 list of interface. Where should I put the call?

#15 mORMot 2 » At client startup - Interface not found fInterfaces.FindHashed(aUri) » 2023-05-09 08:45:18

Replies: 5

Suddenly my testclient crashed at start with an access violation in this call: "HttpClient.Services[DHS_LOCAL_CONTRACT].Get(fDHS_LocalService);"
Debugging showed that the function "fInterfaces.FindHashed(aUri)" returns -1.

I've just added a method to the interface, recompile both the server and client and then this happened. I also removed those changes but still the same problem.
Something else must have been changed but I can't imagine what it could be.

I need some idea of where to start looking. sad

#16 Re: mORMot 2 » IList<T> in services » 2023-05-07 10:36:38

I solved it by replacing IList with an ordinary dynamic array for the service. It requires some more coding but it works. I kept using IList in the repository though as I can initiate the collection in the service before calling the repository methods.

It seems to require too much effort to be worth solving ?

#17 mORMot 2 » IList<T> in services » 2023-05-06 09:31:38

Replies: 3

I'm very fond of IList but I'm trapped by the fact that I have to declare it as a constant in the parameter list on a service method.
So there is no way to initialize it. sad

I'm sure that there is a solution to this but at the moment I'm lost.

#18 Re: mORMot 2 » Multiple field index » 2023-05-06 09:21:06

That looks good, I will soon test it.

#19 mORMot 2 » Multiple field index » 2023-05-05 06:37:49

Replies: 2

Is there a way to have mormot create one index using two or more fields?

#20 Re: mORMot 2 » Invalid pointer operation when using IList with CreateAndFillPrepare » 2023-05-03 21:01:51

Beutifull! Thanks!

This is the result:

function TDHSSyncRepository.GetAllArticles(var aArts: TOrmArticles):TSyncRepoError;
  ormArt: TOrmArticle;
  result := srNotFound;
  FRestOrm.RetrieveIList(TOrmArticle, aArts);
  if aArts.Count < 1 then
  result := srSuccess;

#21 mORMot 2 » Invalid pointer operation when using IList with CreateAndFillPrepare » 2023-05-03 17:27:11

Replies: 2

I get this error when the IList<TOrm> is zero referenced after using CreateAndFillPrepare.

// TOrmArticles is the same as IList<TArticle>
function TDHSSyncRepository.GetAllArticles(var aArts: TOrmArticles):TSyncRepoError;
  ormArt: TOrmArticle;
  i: integer;
  result := srNotFound;
  i := 0;
//  result := Collections.NewList<TOrmArticle>; //Tested doing this call outside/inside this function but same result.
  ormArt := TOrmArticle.CreateAndFillPrepare(FRestOrm,'',[]);
  while ormArt.FillOne do begin
  result := srSuccess;

When aArts no longer used  I get the error.
What's wrong here?

#22 Re: mORMot 2 » How to avoid exception from fields containing null values? » 2023-03-30 10:33:08

Ok, I took a snap from my code and removed a lot of irrelevant code and changed the names in hope that it would be easier to read.
The "names" is just a packed record. I included it in the snap now.

Well, your suggestion worked perfectly.
I remembered when I saw it that I used it before but my memory is just a... memory now I'm afraid.

#23 mORMot 2 » How to avoid exception from fields containing null values? » 2023-03-30 09:41:41

Replies: 2

How should I deal with fields that sometimes contain NULL-values when using variants
The code below shows how I tried to deal with it.
You can't even check if the field is null before using it.
The only way I know is to have a


around each assignment but that doesn't taste good.
I'm sure there is a better solution but I'm lost.

  TNames = packed record
      field1: integer;
      theNullField: RawUTF8;
      field3: RawUTF8;

  I: isqldbrows;
  row: variant;
  names: TNames;
  I := Props.execute('select * from dbo.mytable where name = ?', ['Peter']);
  if I.Step(true) then begin
  names.fImportDir := row.Field1;
  if not row.theNullField. = null then               // This raise an exception
      names.theNullField := row.theNullField      // This also raises an exception if executed.
      names.theNullField := '';
  names.Field3 := row.Field3;

#24 Re: mORMot 2 » Serializing an array of records How To? » 2023-02-23 11:04:33

Ok, that worked well, so many thanks.
I think there are a lot of different ways of doing this and it's hard to find out which method to use.
The project I'm working on now is a replacement of an existing function to make it much faster so the speed is the main purpose of this project.
The reason I want the data of the array stored as JSON is mainly to have better control when testing, perhaps when the application is tested and works well I might consider going back to blob-storage.
But it is still nice to have the possibility to check out the contents in the database.
Any ideas or suggestions are very welcome.

best regards

#25 Re: mORMot 2 » Serializing an array of records How To? » 2023-02-23 09:01:35

Ok, thanks a lot for the almost complete code.
But this one store the week array as a blob, how about having it stored as a JSON string? Wouldn't I need to register the array for JSON?  And what more?
with best regards

#26 Re: mORMot 2 » Serializing an array of records How To? » 2023-02-22 17:05:27

Sorry, the JSON I wrote is not a real JSON array I only typed it in by hand into the database record to test my program.
I'm not sure about how a json string should look to correspond to my class so I'm not surprised that it's not correct.

A Week is a packed record with the name TWeek and then I declared the array TWeekArray from TWeek.
This Array is contained in a class: TWeeks and this class is the one I want to persist in a sqlite3-table. In fact, later I want to have it in an IN-Memory table but in the beginning, I will have it in a database during the test.

So the question is, how can I best persist this table, TWeeks, you have it at the beginning of this thread.
Forget about the JSON string.

#27 Re: mORMot 2 » Serializing an array of records How To? » 2023-02-22 10:04:57

Ok, the compiler is now satisfied but I still missing the data for the WeekArray.

The field "Week" in the db looks like : '{"currentYear": 2023,"ActualWeek": 8,"weeks": [{"ryear": 2023,"rindex": 1,"rweekno": 8,"rAvailableAmt": 186,"rRequiredAmt": 99}]}'.
It's a valid json string but I'm not sure if it is valid in this case?

#28 Re: mORMot 2 » Serializing an array of records How To? » 2023-02-22 09:53:53

Where can I find TRtti? I use System.rtti but that won't help.
Ok, I found it in mormot.core.rtti.
But I couldn't use TRtti but Rtti.

#29 mORMot 2 » Serializing an array of records How To? » 2023-02-22 08:52:22

Replies: 12

I have a class of TSynPersistent containing an array of records that I want to populate from a DB-table.
For the moment while testing, I use SQLite3.

I worked out a TOrm descendant used for reading the data.
Everything reads correctly except for the array which is nil.

I thought I didn't need to register but I now realized that I was wrong.

But I don't know how to do it. Following instructions from the documentation I tried this:

The record:

  TWeek = packed record
    rYear: TYear;
    rIndex: TWeekBufferIndex;
    rWeekNo: TWeekNo;
    rAvailableAmt: TAvailableAmt;
    rRequiredAmt: TRequiredAmt;
    function getAvailableOnWeek: TAvailableOnWeek;
    property availableOnWeek: TAvailableOnWeek read getAvailableOnWeek;
  TWeekArray                 = array of TWeek;

The class:

  TWeeks = class(TSynpersistent)
      fWeekArray  : TWeekArray;
      fActualWeek : TWeekNo;
      function getWeek(index: integer): TWeek;
      procedure SetWeek(const index: integer; aValue: TWeek);
      property weekArray: TWeekArray read fWeekArray write fWeekArray;

The registration:

var T: Pointer;
  T := TypeInfo(TWeekArray);

The TOrm descendant:

  TOrmWeeks = class(TOrm)
      fWeeks      : TWeekArray;
      fActualWeek : TWeekNo;
    constructor create;
      property ActualWeek: TWeekNo read fActualWeek write fActualWeek;
      property Weeks: TWeekArray read fWeeks write fWeeks;

The problem is that the compiler doesn't like this: "  TJSONSerializer.RegisterObjArrayForJSON(T,TWeekArray);"
It say's: [dcc32 Error] dddLOBTypes.pas(294): E2029 '(' expected but ')' found
and next error: [dcc32 Error] dddLOBTypes.pas(295): E2250 There is no overloaded version of 'RegisterObjArrayForJson' that can be called with these arguments

If I replace TWeekArray with a class the compiler will be satisfied.
So what do I missing here?

#30 Re: mORMot 2 » DDD / ORM mapping - PODO -> TOrm » 2023-02-18 15:57:44

So there are no plans to make a new one then?

#31 mORMot 2 » DDD / ORM mapping - PODO -> TOrm » 2023-02-18 13:59:30

Replies: 3

Is there an alternative to mORMot_1:s TDDRepositoryRestFactory.ComputeSQLRecord ?

It would be handy to have one, I've been searching for a while but have not found any.

#32 Re: mORMot 1 » MongoDB - Unsupported OP_QUERY command: hostInfo » 2023-01-17 10:56:55

Ok, that's good. As I'm new to MongoDB it also makes sense to start MongoDB with mORMot2.
When I tried to set up mORMot2 on Delphi and followed the instructions from the ReadMe file I got this code to work.

#33 mORMot 1 » MongoDB - Unsupported OP_QUERY command: hostInfo » 2023-01-17 09:19:06

Replies: 2

Completely new to MongoDB and tried one of your old examples:
https://blog.synopse.info/?post/2014/05 … ase-access

Installed the latest version (6.03) of MongoDB
and tried:

var Client: TMongoClient;
    DB: TMongoDatabase;
    serverTime: TDateTime;
    res: variant; // we will return the command result as TDocVariant
    errmsg: RawUTF8;
  Client := TMongoClient.Create('localhost',27017);
    DB := Client.Database['mydb'];
    writeln('Connecting to ',DB.Name); // will write 'mydb'
    errmsg := DB.RunCommand('hostInfo',res); // run a command
    if errmsg<>'' then
      exit; // quit on any error
    serverTime := res.system.currentTime; // direct conversion to TDateTime
    writeln('Server time is ',DateTimeToStr(serverTime));
    Client.Free; // will release the DB instance

and gets: 'Unsupported OP_QUERY command: db.hostInfo. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal'

Don't know if its possible use the latest version with mORMot1 any more or should I try with mORMot2?

#34 mORMot 1 » Join several levels » 2022-01-20 18:36:04

Replies: 1

Trying to  find the best way to solve the problem with tables in multiple levels as the following example:

TSQLLevel0 = TSQLRecord
  fName: RawUTF8;
  property name: RawUTF8;
TSQLLevel1 = TSQLRecord
  fName: RawUTF8;
   property L1Name: RawUTF8;
   property lev0: TSQLLevel0 read fLev0 write fLev0;

TSQLLevel2 = TSQLRecord
  fName: RawUTF8;
   property L2Name: RawUTF8;
   property lev1: TSQLLevel1 read fLev1 write fLev1;

Tried with CreateJoined but that could only be used on two levels only i.e. Level0 and level1.
Any suggestions would be appreciated.

#35 Re: mORMot 1 » Login fails using TSynConnectionDefinition » 2022-01-01 12:46:19

I don't understand exactly what you meant but I did like this:

fStore: TSynConnectionDefinition;
pw: RawUTF8
    pw := TSynConnectionDefinition.ComputePassword('myPassword');
    fStore := TSynConnectionDefinition.CreateFromJSON(StringToUtf8('{	"Kind": "TOleDBMSSQL2012ConnectionProperties", '
          + '"ServerName": "MyServer\\SQLEXPRESS", "DatabaseName": "MyDB", "User": "username", "Password":  "'+pw+'"}'));
    fDBServer := TSQLRestExternalDBCreate(fModel, fStore, USE_AUTHORIZATION, []);

And that worked, but that wasn't exactly what you said?

#36 mORMot 1 » Login fails using TSynConnectionDefinition » 2021-12-31 12:20:32

Replies: 2

It looked to be convenient to use "TSynConnectionDefinition" but I failed to make it work.
Login failed due to missing password.

My code look like this:

fStore: TSynConnectionDefinition;
 fStore := TSynConnectionDefinition.CreateFromJSON(StringToUtf8('{	"Kind": "TOleDBMSSQL2012ConnectionProperties", '
          + '"ServerName": "MyServer\\SQLEXPRESS", "DatabaseName": "MyDB", "User": "username", "Password": "myPassword"}'));
    fDBServer := TSQLRestExternalDBCreate(fModel, fStore, false, []);

TSQLRestExternalDBCreate looks for fStore.PasWordPlain which does not exist in fStore.

What's wrong with my assumption?

#37 mORMot 1 » Complex join with createJoined » 2021-12-19 17:45:21

Replies: 1

Is the following SQL realizable with the "TSQLRecord.createJoined" function or is there better alternatives?

I try to avoid running the SQL-script in the program due to fear of"SQL-Injection".
It's about an old legacy database. I have tested the function in simpler case where you use only one common field which work perfectly.

SELECT TE.AddressName, TC.Customername FROM tbl_A TA
 join tbl_B TB ON TB.CustomerNo = TA.CustomerNo
 join tbl_C TC ON TC.CustomerNo = TA.CustomerNo
 join tbl_D TD ON TD.CustomerNo = TA.CustomerNo AND TD.AddressNo = TC.AddressNo
 join tbl_E TE ON TE.AddressNo = TD.AddressNo

#38 Re: mORMot 1 » Cannot insert from RestServer » 2021-12-06 16:20:03

Sorry, I fixed it by deleting the table and then run the program again. But Yes I created the table with mORMot but I also have tested different Restservers and it might have been created different then.
I tested TSQLRestClientDB but could not understand how I should set it up. As I don't use SQLITE this time I could not put a filename into the third parameter, I did try but then it created a db3-file with some strange marks ('v') on the tables.

#39 mORMot 1 » Cannot insert from RestServer » 2021-12-06 15:23:01

Replies: 2

I have a small project here where I included everything in one program because it only is about updating a single file with a text field.
My problem is that when the server tries to add a record I'll get an error which says in short: "Cannot insert explicit value into ----- when IDENTITY_INSERT is set to OFF"

I'm running Delphi11 and MSSQL.

Links to part of the code: [URL https://1drv.ms/u/s!AkzgaKIeNifrhaQI3gC … A?e=SpWAz3 /url]

the error message: [URL https://1drv.ms/u/s!AkzgaKIeNifrhaQLwLN … w?e=02zydi /url]

#40 Re: mORMot 1 » Error code: 406 fail on aggregate (ORM.add) » 2021-09-13 17:17:34

Ok, thanks.
Yes, the problem was that I didn't use "TSynAutoCreateFields". After changing that, all is now well.

#41 mORMot 1 » Error code: 406 fail on aggregate (ORM.add) » 2021-09-09 14:00:21

Replies: 2

This happens when I use a class that have references to another class.
see below:

  TLogType = class(TSynPersistent)
      fName: RawUTF8;
      fValue: integer;
      property name: RawUTF8 read fName write fName;
      property value: integer read fValue write fValue;
  TLogTypeObjArray = array of TLogtype;

  TMyLog = class(TSynpersistent)
      fLogdate: TDate;
      fComment: RawUTF8;
      fLogType: TLogType;    <<<<-- the reference
      property logDate: TDate read fLogDate write fLogDate;
      property comment: RawUTF8 read fComment write fComment;
      property logType: TLogType read fLogType write fLogType;

The reference is flattened in the TSQLRecord so the field "LogType" will be two fields:
LogType_Name" and "LogType_value".

Don't have a clue any longer how to solve this. I have a small zip file of a test project to share but don't know where to put it.
The exception occurs in a section called "fake interface" in the mORMot unit.

Would appreciate any help to solve this. Also, a site where I could upload my little zip file (12k).

Maybe this link? https://1drv.ms/u/s!AkzgaKIeNifrhLQze1G … A?e=ZCbpMx

#42 Re: mORMot 1 » How to read from database feeding a filtered list without memory leak » 2021-07-07 13:57:05

Thanks, that was much better - I've already tested and it works perfectly! smile

#43 mORMot 1 » How to read from database feeding a filtered list without memory leak » 2021-07-07 08:14:37

Replies: 2

How to read from database feeding a filtering list without memory leakage?

I have a windows-service that reads data from a table into a TObjectList
which is customized to filter out some data i.e. duplicate records.
That's because I couldn't find out how to do that with SQL and mORMot.
I have created a solution that works but I think it might be a
smarter solution.
Anyone that can tell?

Here is my solution:
Alt 1.

Alt 1. Just need one list and the finally is simpler.
procedure TEvNServer.readPkgPrefix(out aPrefixList: TPrefixList);
  SQL: RawUTF8;
  ppf: TSQLPkgPrefix;
  newPkgPrefix: TSQLPkgPrefix;
  SQL := 'usedBySync = ? ORDER BY DefaultPrefix desc ';
  ppf := TSQLPkgPrefix.CreateAndFillPrepare(fDBServer, SQL, [1]);
  aPrefixList := TPrefixList.create;
    while ppf.FillOne do begin
      newPkgPrefix := TSQLPkgPrefix.create;       // Clone object before adding to list
      newPkgPrefix.assign(ppf);                   //
      if aPrefixList.add(newPkgPrefix) = -1 then  // if object not accepted by the list,
        newPkgPrefix.free;                        // it must be free:d, otherwise mem-leakage
    ppf.free;  // must be free:d otherwise mem-leakage

Alt 2.

Alt 2. Dont need to clone and add the assign method to TSQLPkgPrefix class.
procedure TEvNServer.readPkgPrefix(out aPrefixList: TPrefixList);
  SQL: RawUTF8;
  ppf: TSQLPkgPrefix;
  tmpList: TObjectList<TSQLPkgPrefix>;
  SQL := 'usedBySync = ? ORDER BY DefaultPrefix desc ';
  tmpList := fDBServer.RetrieveList<TSQLPkgPrefix>(SQL, [1], '');
  aPrefixList := TPrefixList.create;
    for ppf in tmpList do begin
      if aPrefixList.add(ppf) = -1 then begin
    if assigned(tmpList) then begin
      tmpList.OwnsObjects := false;

#44 Re: mORMot 1 » Problems with LogViewer and file rotation » 2020-11-05 11:09:59

Don't know where I should set these options/flags and what choices I have?
I skimmed through the Logviewers code but didn't found anything useful.

#45 mORMot 1 » Problems with LogViewer and file rotation » 2020-11-04 10:26:52

Replies: 4

If I open the logfile with the log viewer, while the program is running and produces lines to the log file, and watching it over time the log go nuts!
It seems that the log viewer holds the logfile so that log rotation can not rename the file but still copies and compresses the filecontents into the rotate-list of files.
As it can't begin with an empty file it continues to run the rotate cycle for each line that adds to the log. This will cause huge cpu and memory load.

Is there a way to avoid this and still view the log? It's too easy to forget to close the viewer and unwatched it can cause a mess.

Otherwise I really like the viewer.

#47 mORMot 1 » How create a json formatted array of records? » 2020-08-15 10:47:45

Replies: 2

I tried this:

  body: variant;
  i: integer;
  files: array of RawUTF8;
  atm: array of variant;
  t: variant;
  setLength(files, 2);
  files[0] := 'C:\temp\Faktura_se.pdf';
  files[1] := 'C:\temp\din.pdf';
  if high(files) > -1 then
    SetLength(atm, high(files) + 1);
    for i := 0 to high(files) do
      t.name := extractFileName(files[i]);
      t.value := fileToBase64(files[i]);
      atm[i] := t;
    body.FileAttachments := _arr([atm]);

but that just set FileAttachments to '{"FileAttachments":[null]}'

Is there a simple correction of this code?

#48 Re: mORMot 1 » SynCrtSock error 12019 when run in a VCL-app » 2020-08-15 10:33:14

Found the reason... it was a setting called "Use a Proxy" that was on. I never ever used a proxy before... just don't have a clue on how it was set.
Well, that's it.
Thank's a lot.

#49 Re: mORMot 1 » SynCrtSock error 12019 when run in a VCL-app » 2020-08-14 20:09:47

Ok, but it won't help me as it only works when WIN10 is not detected.
HttpRequest gives error when proxy is set to auto which it is when WIN10 is detected.

What can make it do that? I suppose it normally works with win10?

And when I added "{$R Vista.res}" into the console project it stopped work.

#50 mORMot 1 » SynCrtSock error 12019 when run in a VCL-app » 2020-08-14 10:22:16

Replies: 4

When executing TWinHTTP.Post I get this error when run in a VCL app but if I run an excact copy of the code in a console-app it works.
I have debuged but can't find out what causes this.
Nice if someone have a clue to work on..

I have DELPHI-10.3 in this case and the latest version of WIN10.

I've debugged a bit deeper and found that in the initialization of connection properties there is a selection using Automatic proxy or no proxy. This is controled by OS-Version.
If i run the VCL-app I get major-version=10 and minor=3 but in the console app I get Major=6 and Minor=2 and in that case I get NO_PROXY but in the VCL-app I get Automatic_Proxy.

And if I changed the value from Auto to NO-proxy, using debugger,  it works with the VCL-version.

I have no idea why it is like that and why it won't work with automatic_proxy.
I don't want to change anything in SynCrtSock so I still need some help.

Board footer

Powered by FluxBB