You are not logged in.
Pages: 1
Hi all,
I have the same Invoice class as in the documentation and I want to display the "Details: TInvoiceRecs" on a drawGrid, how can I do this ?
type
TInvoiceRec = record
Ident: RawUTF8;
Amount: currency;
end;
TInvoiceRecs = array of TInvoiceRec;
TSQLInvoice = class(TSQLRecord)
protected
fDetails: TInvoiceRecs;
fTotal: Currency;
procedure SetDetails(const Value: TInvoiceRecs);
published
property Details: TInvoiceRecs read fDetails write SetDetails;
property Total: Currency read fTotal;
end;
Offline
I tryed to serialize the DynArry as JSON but I get a Base64 string, I read the documentation but I don't understand how to do the conversion.
var json : RawUtf8;
inv : TSQLInvoice;
invDets : TInvoiceRecs;
begin
...
try
inv := := TSQLInvoice.CreateJoined(globalClient, fRec.ID);
invDets := inv.Details; <----------------- No Base64
TTextWriter.RegisterCustomJSONSerializer(TypeInfo(TInvoiceRecs), nil, nil);
json := DynArraySaveJSON(invDets, TypeInfo(TInvoiceRecs)); <--------------- Base64
finally
inv.free;
end;
...
Another question :
I added a TSQLArticle property into TInvoiceRec and some others, that works fine when adding records but when I try to load/retrieve the article information I got AV, should I retrieve true instances like with FillPrepareMany for TSQLRecordMany?
type
TInvoiceRec = record
Ident: RawUTF8;
Article: TSQLArticle;
Qty : Double;
Amount: currency;
end;
TInvoiceRecs = array of TInvoiceRec;
I'm on Delphi7.
Offline
First of all, you CAN NOT put an object within a record, then serialize it as JSON!
You can nest records or dynamic arrays, but not class instances!
Record are value objects, here.
Since Delphi 2010, you can serialize directly any record using enhanced RTTI.
For Delphi 7, you have to define your record type in text.
See http://blog.synopse.info/post/2013/12/1 … ialization
and the corresponding part of the documentation.
Something like that for you:
const
__TInvoiceRec = 'Ident RawUTF8 Article TArticleRec Qty double Amount currency';
__TArticleRec = '....';
...
TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TArticleRec),__TArticleRec);
TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TInvoiceRec),__TInvoiceRec);
// now Delphi 7 will serialize any TInvoiceRec or TInvoiceRecs values as JSON!
Here, TArticleRec being a record, not a class.
Offline
Well, I think that I'll replace the sharding by a RecordMany class because in my business logic an invoice record can have many TSQLArticle instances.
I'm right or there's another way to do that ?
thnx for all explanations
Offline
What I want to is simple, I have some classes like this
TsqlArticle=(Name, Brand, Family ...)
TsqlInvoice=(like documentation)
Each invoice can have several Articles (pivot table in RAD).
I want that the ui be able to add the invoice and details at once like in RAD. I'm using fastreport for some reasons and I need to serialize the invoice with details to dataset.
Offline
Hi AB,
I've transformed my sharding invoice details into TSQLRecordMany and it works correctly. Now I want to calculate some invoice totals automaticly after adding TSQLRecordMany records, is there a call back/event triggered after ManyAdd() function ?
thnx,
Offline
Pages: 1