Setting properly a dblookupcombobox for a subproperty level 2

I have this :

TLot_in = class
private
[Column('ID', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
FID: Integer;

[Column('Code', [], 15)]
FCode: Nullable<string>;

[Column('Qty', [], 10, 0)]
FQty: Nullable<Double>;

[Column('TimeStamp', [TColumnProp.Required])]
FTimeStamp: TDateTime;

[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('Id_rawproduct', [], 'ID')]
FRawProduct: Proxy<TrawProduct>;

[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('ID_doc', [], 'ID')]
FDoc: Proxy<TDoc>;

[ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FLot_In')]
FLot_Outs: Proxy<TList<TLot_Out_Entrie>>;
function GetRawProduct: TrawProduct;
procedure SetRawProduct(const Value: TrawProduct);
function GetDoc: TDoc;
procedure SetDoc(const Value: TDoc);
function GetLot_Outs: TList<TLot_Out_Entrie>;

Doc property has an association with TSupplier . I set a dblookupcombobox for the TLot_in.Doc.Supplier field :

   object cxDBLookupComboBox1: TcxDBLookupComboBox
      Left = 69
      Top = 12
      DataBinding.DataField = 'Doc.Supplier'
      DataBinding.DataSource = DM.srcLot_In
      Properties.KeyFieldNames = 'Self'
      Properties.ListColumns = <
        item
          FieldName = 'Rag_soc'
        end>
      Properties.ListSource = DM.srcSupplier
      Style.HotTrack = False
      Style.TransparentBorder = False
      TabOrder = 0
      Width = 247
    end

when I try to do dsLot_in.post an error is raised :

where I’m in error?

Not tried or tested this, but check out: Data Binding - TAureliusDataset | TMS Aurelius documentation

It's important to note that sub-property fields are not created by default when using default fields. In the example of TCustomer class above, only field "Country" will be created by default, but not "Country.Name" or any of its sub-properties. To use a sub-property field, you must manually add the field to the dataset before opening it.

I believe there's also a DataSet property to specify how many levels you want to import when reading FieldDefs.

I set the SubpropsDepth property to 3 and automatically the dataset has created all field up to that depth, but still not working

Also make sure the Supplier (level 2 property) exists. Perhaps you need to do something like this first:

TLot_In.Supplier.AsObject := TSupplier.Create;

Otherwise the Supplier property is nil and you cannot set its properties.

Apologies if I’m stating the obvious, but sometimes that’s required :wink: . I just struggled with an XData Server, only to find out I accidentally had an illegal fieldname for SQL Server….

I notice the name of field in the error message (supplier) is not the same of that the dataset has created (doc.supplier). could this be a clue? What the synsubprops property does?

Perhaps the dot in then name of field (doc.supplier) is a problem

Don't apologize. Sometimes we make trivial mistakes.

SyncSubProps: Boolean

Allows automatic updating of associated fields. When an entity field (e.g., "Customer") of the TAureliusDataset component is modified, all the subproperty fields (e.g., "Customer.Name", "Customer.Birthday") will be automatically updated with new values if this property is set to True. Default is False.

:frowning:

it was sufficient to add this

procedure TDM.dsLot_InBeforeCancel(DataSet: TDataSet);
begin
if Assigned( dsLot_InDoc.AsObject as TDoc) then
Tdoc(dsLot_InDoc.AsObject).Free

end;

procedure TDM.dsLot_InNewRecord(DataSet: TDataSet);
begin
dsLot_InTimeStamp.Value := Now;
dsLot_InDoc.AsObject := TDoc.Create

end;

about trivial things …

:slight_smile:

That is what I meant when I wrote:

Also make sure the Supplier (level 2 property) exists. Perhaps you need to do something like this first:

TLot_In.Supplier.AsObject := TSupplier.Create;

Good to see you have it solved!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.