You are not logged in.
Pages: 1
I really like the idea of the Dynamic arrays and packed records and it 'hashed' features, multi-sort etc. Very very nice thinking!
I'm trying to use DynArrs in my ORM classes, but maybe I'm looking at it wrong:
type TContactAttachType = set of (ifFile,itPhoto,itLogo);
type TContactAttachment = packed record
fAttachType : TContactAttachType;
fAttachID : Integer;
property AttachType : TContactAttachType read fAttachType write fAttachType;
property AttachID : Integer read fAttachID write fAttachID;
end;
TContactAttachArr=Array of TContactAttachment;
type TSQLContact = class(TSQLRecord)
private
fName : RawUTF8;
fAttach : TContactAttachArr;
published
property Name : RawUTF8 read fName write fName;
property Attachments : TContactAttachArr read fAttach write fAttach;
end;
Very cool as I can write simple code to fill e.g. custom Dataset for UI:
for ATT in Contact.Attachments do
begin
CP.Insert;
CPName .AsString :=ATT.Number;
CPFile .AsBoolean:=ptFile in ATT.PhoneType;
CPPhoto .AsBoolean:=ptPhoto in ATT.PhoneType;
CPLogo .AsBoolean:=ptLogo in ATT.PhoneType;
CP.Post;
end;
But to write/change data via the property I'm having a problem:
DA.Init(TypeInfo(TContactAttachment),Item.Attachments,@DAC);
DA.Capacity:=CP.RecordCount;
SetLength(Item.Attachments,CP.RecordCount);
Both cannot compile as I need to access the private variable of TSQLContact.fAttach?
How can I overcome this without polluting the TSQLContact with UI related code?
Or am I looking at it wrong?
Thanks
Regards
AntonE
Last edited by AntonE (2014-07-03 09:13:36)
Offline
You can either:
- add an "index ###'" to the dynamic array field, then use the TSQLRecord.DynArray(DynArrayFieldIndex) method;
- or use the TSQLRecord.DynArray(DynArrayFieldName) method
to retrieve a TDynArray instance without exposing the row fAttach protected member.
Online
Pages: 1