#1 2017-09-14 18:39:27

ertank
Member
Registered: 2016-03-16
Posts: 168

Proper way to use Delphi 10.2 DLL in a Delphi 7 application (json)

Hello,

I always used mORMot with recent Delphi versions and had no problems until today. Now, I am in a project where I need to use (my side) Delphi 10.2 to build a DLL for SOAP Web Service consuming. That DLL functions are allocating WideString to put json inside and returning these WideStrings to (other party) Delphi 7 application to use.

We are proceeding method by method. Our first methods we did not use any json on Delphi 7 side. They were only WideString information going back and forth. We now reached our first method to utilize json usage and I realize that mORMot needs a slightly modified FastMM for Delphi 7. Other party put all necessary files in place. First line of the project dpr file is modified to use "FastMM4". Project compiles fine.

When they we call json string returning DLL function, it is all garbage text received as a reply.

I have no experience using mORMot with Delphi 7 and asking for help in here.

Is there anything we should be doing in order to make above explained scenario to work?

Thanks & regards,

Ertan

Offline

#2 2017-09-14 19:44:18

ertank
Member
Registered: 2016-03-16
Posts: 168

Re: Proper way to use Delphi 10.2 DLL in a Delphi 7 application (json)

***Correction***

I just learned that problem exists in Delphi 7 before calling DLL function. Delphi 7 is to prepare Json string and send it as a constant WideString to DLL function. What is prepared using RecordSaveJSON() seems to be non-readable text. Details as below:

Record definitions:

  TOlcumBilgileriInput = packed record
    kantarNo: string;
    turu: string;
    tartimTarihi: TDateTime;
    tartimSaati: string;
    dbaBelgeNo: string;
    operatorNo: string;
    konteynerNo: string;
    konteynerPayLoad: Double;
    operatorTcNo: string;
    operatorAdSoyad: string;
    olcumSonucu: Double;
    arac1Plaka: string;
    arac1BosAgirlik: Double;
    arac2Plaka: string;
    arac2BosAgirlik: Double;
    konteynerDara: Double;
    yukletenVergiNo: string;
    yukletenUnvan: string;
    gidecegiLimanId: Double;
  end;

Code calling RecordSaveJSON():

var
  OBI: TOlcumBilgileriInput;
  Json: RawUTF8;
begin
  OBI.kantarNo          := '1031';
  OBI.turu              := 'YON1';
  OBI.tartimTarihi      := EncodeDate(2017, 1, 1);
  OBI.tartimSaati       := FormatDateTime('hh:nn', EncodeTime(11, 24, 0, 0));
  OBI.dbaBelgeNo        := 'BKN.656178.Y-1.41.9';
  OBI.operatorNo        := EmptyStr;
  OBI.konteynerNo       := '123456';
  OBI.konteynerPayLoad  := 123456;
  OBI.operatorTcNo      := '23851792108';
  OBI.operatorAdSoyad   := 'TEST PERSON';
  OBI.olcumSonucu       := 321;
  OBI.arac1Plaka        := '41VV524';
  OBI.arac1BosAgirlik   := 121;
  OBI.arac2Plaka        := EmptyStr;
  OBI.arac2BosAgirlik   := 0;
  OBI.konteynerDara     := 12;
  OBI.yukletenVergiNo   := '1030050950';
  OBI.yukletenUnvan     := 'SOME COMPANY NAME HERE';
  OBI.gidecegiLimanId   := 715525;

  Json := RecordSaveJSON(OBI, TypeInfo(TOlcumBilgileriInput));

At this point variable Json having below value:

"ï¿°BDEwMzEEWU9OMQAAAAAA3uRABTExOjI0E0JLTi42NTYxNzguWS0xLjQxLjkABjEyMzQ1NgAAAAAAJP5ACzIzODUxNzkyMTA4DkVSRE/QQU4g1lpLQVlBAAAAAAAQdEAHNDFWVjUyNAAAAAAAQF5AAAAAAAAAAAAAAAAAAAAAKEAKMTAzMDA1MDk1MDtFVllBUCBERU7dWiDd3kxFVE1FQ91M3dDdIExPSt1TVN1LIFZFIN1O3kFBVCBBTk9O3U0g3t1SS0VU3QAAAAAK1iVB"

Seems like Base64 converted text.

Last edited by ertank (2017-09-14 19:44:55)

Offline

#3 2017-09-14 19:54:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: Proper way to use Delphi 10.2 DLL in a Delphi 7 application (json)

Check the documentation.
Delphi 7 has not enough rtti: it needs text definition of the record.

Offline

#4 2017-09-14 21:13:08

ertank
Member
Registered: 2016-03-16
Posts: 168

Re: Proper way to use Delphi 10.2 DLL in a Delphi 7 application (json)

Hello ab,

Thank you for the tip.

I could not get much help from documentation. I found some information in section "10.1.3.2 Serialization for older Delphi versions". However, your blog post in below link was in detail and helped me a lot.
http://blog.synopse.info/post/2013/12/1 … ialization

My current code is as follows. All is working just fine at the moment. As I had national language issues, I converted all string variables to RawUTF8.

unit uDefines;

interface

uses
  SynCommons;

const
  RESPONSE_OK = 0;
  SOAP_ERROR = 1;
  SOAP_ERROR_CREATE = 2;
  SOAP_ERROR_ADD_RECORD = 3;
  JSON_EMPTY = 4;
  JSON_BAD_FORMAT1 = 5;
  JSON_BAD_FORMAT2 = 6;
  JSON_ERROR = 7;

var
  __OlcumBilgileriInput: string;
  __OlcumBilgileriSonuc: string;

type
  TOlcumBilgileriInput = packed record
    kantarNo: RawUTF8;
    turu: RawUTF8;
    tartimTarihi: TDateTime;
    tartimSaati: RawUTF8;
    dbaBelgeNo: RawUTF8;
    operatorNo: RawUTF8;
    konteynerNo: RawUTF8;
    konteynerPayLoad: Double;
    operatorTcNo: RawUTF8;
    operatorAdSoyad: RawUTF8;
    olcumSonucu: Double;
    arac1Plaka: RawUTF8;
    arac1BosAgirlik: Double;
    arac2Plaka: RawUTF8;
    arac2BosAgirlik: Double;
    konteynerDara: Double;
    yukletenVergiNo: RawUTF8;
    yukletenUnvan: RawUTF8;
    gidecegiLimanId: Double;
  end;

  TOlcumBilgileriSonuc = packed record
    sonucKodu: Integer;
    sonucMesaji: RawUTF8;
    udhbOlcumSonucId: Int64;
  end;

implementation


initialization
  __OlcumBilgileriInput := 'kantarNo RawUTF8 turu RawUTF8 tartimTarihi TDateTime tartimSaati RawUTF8 dbaBelgeNo RawUTF8 operatorNo RawUTF8 konteynerNo RawUTF8 konteynerPayLoad Double operatorTcNo RawUTF8 operatorAdSoyad RawUTF8 ' +
                           'olcumSonucu Double arac1Plaka RawUTF8 arac1BosAgirlik Double arac2Plaka RawUTF8 arac2BosAgirlik Double konteynerDara Double yukletenVergiNo RawUTF8 yukletenUnvan RawUTF8 gidecegiLimanId Double';
  __OlcumBilgileriSonuc := 'sonucKodu Integer sonucMesaji RawUTF8 udhbOlcumSonucId Int64';

  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TOlcumBilgileriInput), __OlcumBilgileriInput);
  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TOlcumBilgileriSonuc), __OlcumBilgileriSonuc);
end.

Offline

Board footer

Powered by FluxBB