Property name is invalid or subproperty is inaccessible.

Hi!

I'm trying to create an edit form to allow users to insert new records in the DB. The forma has a TLookupcomboBox, a dataset for editing (adsEdit) and a dataset for a lookup (adsOwners).

I see the values in the lookup, but when I do adsEdit.Post, I get this error:

Cannot set value of property "OwnerId". Either property name is invalid or subproperty is inaccessible.

Entities:

  [Entity]
  [Table('Abonma')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TAbonma = class
  private
    [Column('Id', [TColumnProp.Required])]
    FId: Integer;
    
    [Column('ValidFrom', [TColumnProp.Required])]
    FValidFrom: TDateTime;
    
    [Column('ValidTo', [TColumnProp.Required])]
    FValidTo: TDateTime;
    
    [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('OwnerId', [], 'Id')]
    FOwnerId: Proxy<TOwner>;

    function GetOwnerId: TOwner;
    procedure SetOwnerId(const Value: TOwner);
  public
    property Id: Integer read FId write FId;
    property ValidFrom: TDateTime read FValidFrom write FValidFrom;
    property ValidTo: TDateTime read FValidTo write FValidTo;
    property OwnerId: TOwner read GetOwnerId write SetOwnerId;
  end;

  [Entity]
  [Table('Owners')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TOwner = class
  private
    [Column('Id', [TColumnProp.Required])]
    FId: Integer;
    
    [Column('FirstName', [], 50)]
    FFirstName: Nullable<string>;
    
    [Column('LastName', [], 50)]
    FLastName: Nullable<string>;
    
    [Column('Active', [TColumnProp.Required])]
    FActive: Integer;
  public
    property Id: Integer read FId write FId;
    property FirstName: Nullable<string> read FFirstName write FFirstName;
    property LastName: Nullable<string> read FLastName write FLastName;
    property Active: Integer read FActive write FActive;
  end;

edsEdit.SubPropsDepth = 1;
edsEdit.SyncSupProps = true;
edsEdit.CreateSelfField = true;

Since I don't know what extra info to attach, please let me know if you need additional informations.

Any tips..?

How is your lookup combo box configured? What properties did you set, and how?

  object adsEdit: TAureliusDataset
    FieldDefs = <>
    SubpropsDepth = 1
    SyncSubprops = True
    Left = 105
    Top = 161
    object adsEditId: TIntegerField
      FieldName = 'Id'
    end
    object adsEditOwnerId: TIntegerField
      FieldName = 'OwnerId'
    end
    object adsEditLocationId: TIntegerField
      FieldName = 'LocationId'
      LookupDataSet = adsLocations
    end
    object adsEditValidFrom: TDateTimeField
      FieldName = 'ValidFrom'
    end
    object adsEditValidTo: TDateTimeField
      FieldName = 'ValidTo'
    end
  end

  object cbxOwner: TDBLookupComboBox
    Left = 100
    Top = 16
    Width = 281
    Height = 21
    DataField = 'OwnerId'
    DataSource = srcEdit
    KeyField = 'Self'
    ListField = 'FirstName'
    ListSource = srcOwners
    TabOrder = 1
  end

OwnerId is an entity (an object) and thus should be declared as TAureliusEntityField, not TIntegerField. Maybe that's causing the issue.

Changet adsEdit to suggested, but no change in the error

  object adsEdit: TAureliusDataset
    FieldDefs = <>
    SubpropsDepth = 1
    SyncSubprops = True
    Left = 105
    Top = 161
    object adsEditId: TIntegerField
      FieldName = 'Id'
    end
    object adsEditOwnerId: TAureliusEntityField
      FieldName = 'OwnerId'
    end
    object adsEditLocationId: TAureliusEntityField
      FieldName = 'LocationId'
    end
    object adsEditValidFrom: TDateTimeField
      FieldName = 'ValidFrom'
    end
    object adsEditValidTo: TDateTimeField
      FieldName = 'ValidTo'
    end
  end

Found the error! I was using a wrong class (TOwner instead of TAbonma) for the main dataset.

Mea culpa, father :slight_smile:

But your suggestion also worket, so it's been worthi it :slight_smile:

Thanx again!

1 Like

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