Show/Hide Toolbars

TMS Aurelius Documentation

Navigation: Data Binding - TAureliusDataset > Using Fields

Entity Fields (Associations)

Scroll Prev Top Next More

Entity Fields are fields that maps to an object property in a container object. In other words, entity fields represent associations in the object. Consider the following class:

 

  TCustomer = class

  // <snip>

  public

    property Id: Integer read FId write FId;

    property Name: string read FName write FName;

    property Country: TCountry read FCountry write FCountry;

  end;

 

By default, TAureliusDataset will create fields "Id" and "Name" (scalar fields) and "Country" (entity field). An entity field is just a field of type TAureliusEntityField that holds a reference to the object itself. Since Delphi DB library doesn't  provide a field representing an object pointer (which makes sense), this new field type is provided by TMS Aurelius framework for you to manipulate the object reference.

 

The TAureliusEntityField is just a TVariantField descendant with an additional AsObject property, and an addition generic AsEntity<T> function that you can use to better manipulate the field content. To access such properties, you can just cast the field to TAureliusEntityField, or use TAureliusDataset.EntityFieldByName method.

 

Please note that the entity field just represents an object reference. It's useful for lookup fields and to programatically change the object reference in the property, but it's not useful (and should not be used) for visual binding, like a TDBGrid or to be edited in a TDBEdit, since its content is just a pointer to the object. To visual bind properties of associated objects, use sub-property fields.

 

The following code snippets are examples of how to use the entity field.

 

// following lines are equivalent and illustrates how to set an association through the dataset

AureliusDataset1.EntityFieldByName('Country').AsObject := TCountry.Create;

(AureliusDataset1.FieldByName('Country'as TAureliusEntityField).AsObject := TCountry.Create;

 

Following code shows how to retrieve the value of an association property using the dataset field:

 

Country := AureliusDataset1.EntityFieldByName('Country').AsEntity<TCountry>;