You are not logged in.
I wrote a unit to convert TSQLRecord and it's sub-arrays/records to Nested TClientdatasets.
Some key features:
Create TClientdataset hierarchy dynamically based on data.
Also work with static TClientDatasets+Static fields.
Handle sub-TSQLRecord lists. (See sample)
Convert Set of ENUM to/from multiple Boolean fields for grid checkboxes
Most importantly: Apply delta-changes back to mORMot. i.e. only changed fields.
(With RTTI adjustments), should work on any platform that support TClientdataset, e.g. Intraweb
It is very first version so not tested on insert/delete yet nor many types of data, guaranteed to be buggy & lacking at this stage, but working.
ftp://ftp.true.co.za/ORMCDS.7z (Working in Delphi XE4 with JEDI installed for TJvDBUltimGrid, change to TDBGrid if needed.)
In demo:
Choose Static or Dynamic demo, select 'Load' to load data, edit any field or nested data, click 'Apply'.
Best is to see code to get more info.
My first try with RTTI and new at mORMot so I'm sure it could have been done more elegantly with mORMot's RTTI built-support.
Also not optimized for speed but should be pretty fast.
Regards
Antone
Last edited by AntonE (2014-12-01 16:15:08)
Offline
@AntonE,
Nice, but could you use the convention?
ATypeInfo^.TypeData^.ClassType => GetTypeData(ATypeInfo).ClassType
BInfo.CDS.RecNo.ToString => IntToStr(BInfo.CDS.RecNo)
Older Delphi (eg. XE2) does not compile this.
Michal
Last edited by miab3 (2014-12-01 15:46:14)
Offline
Thanks for that, I updated the files.
Offline
Nice.
I've uploaded this project to the "Third party" folder.
See http://synopse.info/fossil/info/6babeae8b2
May be a good start to enhance our TSynVirtualDataSet so that it would support updates.
Online
Ok, I've improved quite a bit since that version, will upload soon.
I'll check out TSynVirtualDataset.
AntonE
Offline
I uploaded an updated version to that same link above.
Fixed a few bugs a.o. adding/deleting items in a DynArray.
However, I have a problem with memory leaks using DynArrays, but only when resizing them. It seems when a copy is made, I'm not deferencing the old copy properly.
If I run FastMM4 in FullDebugMode I even get error that memory that is freed are referenced and the app crash. Without FullDebugMode I get AnsiString memory leaks (when resizing arrays) but the app works fine. (Win32). In ORMCDS.pas lines 537 onwards is where the trouble lies I think.
I've tried various methods, using mORMot TDynArray and Rtti but it seems it's in the usage of TValue that old reference to array does not get cleaned up, so not production ready yet.
Regards
Offline
Hey Arnaud, thanks for doing this to my little unit.
I'm redoing it in a more mORMot way using TSQLPropInfoRtti family.
How do I get a DynArray element type from TSQLPropInfoRTTIDynArray ?
Once I have an instance, I can get it from TDynArray.ElemType but I need to construct from TSQLRecordClass.
...or must I still use Delphi Rtti to get that?
Also, if a DynArray have Record as element type, how do I get TSQLPropInfoRecordRTTI for that type? I can only see how to construct TSQLPropInfoRecordRTTI as a new member, don't know how to reference it for arbitrary type.
Thanks
Regards
Last edited by AntonE (2014-12-17 11:00:42)
Offline
Sorry for the mind crash...
Take a look at the following section of mORMot.pas:
{ ************ some RTTI and SQL mapping routines }
and use directly PClassProp and PPropInfo to work with objects, and our PTypeInfo as a low-level object type, instead of TypInfo.pas.
BTW using these structures instead of the Delphi RTTI.pas unit would also make your code FPC compatible, or also work with older versions of Delphi.
Online
I'm afraid I'm still a bit in the dark with mORMot's Rtti. Using TSQLRecord is easy with PPropInfo, etc.
But how do I enumerate a record type similar to this with mORMot's built-in functions ?:
function EnumRecordType(ATypeInfo:PTypeInfo):RawUTF8;
var Ctx : TRttiContext;
Rec : TRttiRecordType;
Fld : TRttiField;
begin
Ctx:=TRttiContext.Create;
Rec:=TRttiRecordType(Ctx.GetType(ATypeInfo));
for Fld in Rec.GetFields do
Result:=Result+Fld.Name+' : '+Fld.FieldType.Handle^.Name+#13#10;
Ctx.Free;
end;
Trying to use code below but do not know how to get record field names:
function EnumRecordType(ATypeInfo:PTypeInfo):RawUTF8;
var RecType : PRecordType;
RecField : PRecordField;
begin;
RecType:=ATypeInfo^.RecordType;
for I:=0 to Pred(RecType.Count) do
begin
RecField:=@RecType.Fields[i];
(*How to get field name, not just type name*)
Result:=Result+RecField^.TypeInfo^.{Field?}Name+' : '+RecField^.TypeInfo^.Name;
case RecField^.TypeInfo^.Kind of
tkDynArray : begin
end;
end;
end;
TSQLPropInfoRecordRTTI seems to have the fields/methods I need but it is only used as an object's published properties? Or how can I instantiate it for any record type?
Thanks
AntonE
Offline
Sorry to post here. But there is an error when you try to create a new Post new topic on this forum:
An error was encountered
Error: Could not connect to smtp host "217.70.184.11" (110) (Connection timed out).
Last edited by Kobe (2014-12-18 11:15:45)
Offline