TDAFieldRules

Overview

The TDAFieldRules class represents a collection of Business Rules for custom strongly typed fields.

To learn more about business rules, pleasr refer to the article .

The TDAFieldRules class provides the field implementation of the event handlers (i.e. OnValidate and OnChange). You do not need to use this class directly, but you can use the descendants of this class while setting specified Business Rules for custom strongly typed fields. The descendants of the TDAFieldRules class provide specified business logic for custom fields.

For example: After creating strongly typed fields with the menu option "Generate SampleSchema strongly-typed access units", the strongly typed fields ancestor and descendant classes will have the following structure (the code was taken from the DataAbstract sample "Strongly Typed"):

  { TBizCustomerIDRules }
  TBizCustomerIDRules = class(TDAFieldRules)
  private
  protected
    procedure OnValidate(Sender: TDACustomField); override;
    procedure OnChange(Sender: TDACustomField); override;
  end;

  [..]

implementation

{ TBizCustomerIDRules }

procedure TBizCustomerIDRules.OnChange(Sender: TDACustomField);
var i : integer;
    lCurrVal : string;
begin
  lCurrVal := Sender.AsString;
  for i := 1 to Length(lCurrVal) do
    if not (lCurrVal[i] in ['a'..'z', 'A'..'Z', '0'..'9'])
      then raise EDABizValidationException.Create('Invalid character');
end;

procedure TBizCustomerIDRules.OnValidate(Sender: TDACustomField);
begin
  beep;
end;

initialization
  RegisterFieldRules('CustomerID', TBizCustomerIDRules);

Location

 

constructor Create  virtual    (declared in TDABusinessRules)

Creates a new instance.

constructor Create

constructor Create (TDAField, TDADataTable)  reintroduce virtual

Creates a new instance.

constructor Create(aField: TDAField; aDataTable: TDADataTable)

Parameters:

  • aField: field
  • aDataTable: datatable

Attach  protected virtual

Empty method. Descendants may override it to perform additional actions.

procedure Attach(aDataTable: TDADataTable)

Parameters:

  • aDataTable: Specified data table that should be attached

DataTable  protected

Owner's datatable.

property DataTable: TDADataTable read write

Detach  protected virtual

Empty method. Descendants may override it to perform additional actions.

procedure Detach(aDataTable: TDADataTable)

Parameters:

  • aDataTable: Specified data table that should be detached

OnChange  protected virtual

Fires whenever the value of a particular field has been changed.

procedure OnChange(Sender: TDACustomField)

Parameters:

  • Sender: sender instance

OnValidate  protected virtual

Fires whenever the value of a particular field is about to change, given the event handler opportunity to validate and possibly reject the change by raising an exception.

procedure OnValidate(Sender: TDACustomField)

Parameters:

  • Sender: sender instance

 

DataTable  protected

Owner's datatable.

property DataTable: TDADataTable read write

 

constructor Create  virtual    (declared in TDABusinessRules)

Creates a new instance.

constructor Create

constructor Create (TDAField, TDADataTable)  reintroduce virtual

Creates a new instance.

constructor Create(aField: TDAField; aDataTable: TDADataTable)

Parameters:

  • aField: field
  • aDataTable: datatable

Attach  protected virtual

Empty method. Descendants may override it to perform additional actions.

procedure Attach(aDataTable: TDADataTable)

Parameters:

  • aDataTable: Specified data table that should be attached

Detach  protected virtual

Empty method. Descendants may override it to perform additional actions.

procedure Detach(aDataTable: TDADataTable)

Parameters:

  • aDataTable: Specified data table that should be detached

OnChange  protected virtual

Fires whenever the value of a particular field has been changed.

procedure OnChange(Sender: TDACustomField)

Parameters:

  • Sender: sender instance

OnValidate  protected virtual

Fires whenever the value of a particular field is about to change, given the event handler opportunity to validate and possibly reject the change by raising an exception.

procedure OnValidate(Sender: TDACustomField)

Parameters:

  • Sender: sender instance

See Also

  • Business Rules
  • Strongly Typed DataTables and Business Helper Classes (Delphi)