You are not logged in.
Pages: 1
I have my class :
TIndex = class ( TRemotable )
private
fField : string ;
fCond : string ;
FVal : WideString ;
published
property Afield : String read write fField fField / / Field Name
ACOND property : String read write fCond fCond / / Condition
Aval property : WideString read FVal FVal write / / Value (s )
end ;
TIndexStructure = array of TIndex ;
.....
code to initialize :
var
v_index : TIndexStructure ;
v_count : Integer;
begin
try
SetLength ( v_index , cdsIndex.RecordCount ) ;
cdsIndex.First ;
v_count : = 0;
while not the cdsIndex.Eof
begin
v_index [ v_count ] : = tIndex.Create ;
. v_index [ v_count ] Afield : cdsIndex.FieldByName = ( ' AINDEX ' ) Value; .
. v_index [ v_count ] ACOND : cdsIndex.FieldByName = ( ' ACOND ' ) AsString ; [1] .
. v_index [ v_count ] Surety : cdsIndex.FieldByName = ( ' AVAL ' ) Value; .
Inc ( v_count , 1);
cdsIndex.Next ;
end ;
except
...
end ;
end ;
question :
HOW DO I TURN THIS IN CLASS JSON ?
Offline
Did you try the ObjectToJSON() function in mORMot.pas?
Note that all your code is not at all mORMot-based.
This TRemotable class is not handled at all by the framework.
But ObjectToJSON() is able to serialize any class with published properties.
Offline
ok.
I am developing a webservice (dll).
I changed my code:
TIndex= class(TPersistent)
private
fField:string;
fCond:string;
fVal:WideString;
published
property AField:string read fField write fField; //Nome do campo
property ACond:string read fCond write fCond; //Condicao
property AVal:WideString read fVal write fVal; //Valor(es)
end;
TIndexStructure = array of TIndex;
TInsReg = class(TPersistent)
private
fIdent : RawUTF8;
fIdSetup : RawUTF8;
fObs : TSQLRawBlob;
fPriority: Integer;
fRefCond : RawUTF8;
fRefVal : RawUTF8;
FIndex : TIndexStructure;
published
property AIdent : RawUTF8 read fIdent write fIdent;
property AIdSetup : RawUTF8 read fIdSetup write fIdSetup;
property AObs : TSQLRawBlob read fObs write fObs;
property APriority: Integer read fPriority write fPriority;
property ARefCond : RawUTF8 read fRefCond write fRefCond;
property ARefVal : RawUTF8 read fRefVal write fRefVal;
property AIndex : TIndexStructure read FIndex write FIndex;
end;
------
I need to send (client side) and receive (webservice side) class TInsReg.
I thought about doing this with the function call:
fn_InsReq function (AInsRegSend: RawJSON): RawUTF8;
-------------------
I already do it by delphi but I'm wanting to use mormot.
In your opinion, how should I proceed for this?
How should I serialize (JSON), the client side, and to send and receive in webservice side and unserialize?
Thanks foe your hep.
Offline
Dynamic array of classes is not handled by the RTTI, nor mORMot.
Use a dynamic array of records instead.
Then call ObjectToJSON() and JSONToObject() from mORMot.pas.
Ensure you took a look at record serialization.
Could be even easier than classes in your case.
See http://blog.synopse.info/post/2013/12/1 … ialization and the "Text-based definition" paragraph.
Offline
Wonder. Thanks for the tips. See how it fits:
type
TInsReg = packed record
fIdent : RawUTF8;
fIdSetup : RawUTF8;
fObs : TSQLRawBlob;
fPriority: Integer;
fRefCond : RawUTF8;
fRefVal : RawUTF8;
fIndex : array of record
fField: RawUTF8;
fCond : RawUTF8;
fVal : TSQLRawBlob;
end;
end;
const
__TInsReg = 'fIdent RawUTF8 fIdSetup RawUTF8 fObs RawUTF8 fPriority Integer fRefCond RawUTF8 fRefVal RawUTF8 fIndex[fField RawUTF8 fCond RawUTF8 fVal RawUTF8]';
TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TInsReg),__TInsReg);
..............
It worked perfectly. My last question in this context. How do I define the TSQLRawBlob const __ TInsReg?
When I set so I get an error that is TSQLRawBlob not recognized.
__TInsReg = 'fIdent RawUTF8 fIdSetup RawUTF8 fObs TSQLRawBlob fPriority Integer fRefCond RawUTF8 fRefVal TSQLRawBlob fIndex[fField RawUTF8 fCond RawUTF8 fVal TSQLRawBlob]';
Offline
Oups... this is missing...
I've just added RawByteString support for text-based record serialization, using Base-64 encoding.
See http://synopse.info/fossil/info/5dc231900e
Offline
Thank you very much.
Now, one more question. In my webservice (dll) I can use, or has the logs?
If yes, tell me how to do.
Offline
Pages: 1