Board index » delphi » BO visible for data-aware controls

BO visible for data-aware controls

Hi,
With no very deep knowledge on OPF, I built my trial of Business Objects for
my applications. At code level, it has beel useful since I don't deal with
database fields. Yet I have the problem on how to make my poperties avaiable
for data aware controls; for UI I'm still attached to database fields.

My BO definition is basically as follows:
------------
  TBusinessObject = class(TPersistent)
  private
    FOIDField: string;
    FDataSet: TDataSet;
    procedure SetDataSet(const Value: TDataSet);
    procedure SetOIDField(const Value: string);

  public
    property DataSet: TDataSet read FDataSet write SetDataSet;
    property OIDField: string read FOIDField write SetOIDField;    // Needed
for a base class form I use for BOs.

    procedure WriteProperty( DBField: string; Value: Variant );
    function  ReadProperty( DBField: string ): Variant;

    constructor Create( DataSet: TDataSet; OIDField: string ); overload;
....

procedure TBusinessObject.WritePropety(DBField: string; Value: Variant);
begin
  DataSet.FieldValues[ DBField ]:= Value;
end;

function TBusinessObject.ReadProperty(DBField: string): Variant;
begin
  Result:= DataSet.FieldValues[ DBField ];
end;

----------------

An example of the instance of this class would be:

  TCustomer = class( TBusinessObject )
  private
    function ReadName: Variant;
    procedure SetName(const Value: Variant);
  public
    property Name: Variant read ReadName write SetName;
  end;
.....
function TCustomer.ReadName: Variant;
begin
  Result:=ReadProperty( 'CustomerName' );
end;

procedure TCliente.SetpNombre(const Value: Variant);
begin
  WriteProperty( 'CustomerName', Value );
end;

..........
  boCustomer: TCustomer;
...........
 boCustomer:=  TCustomer.Create( ClientDataSetCustomer, 'OID_CUSTOMER' );

--------------
Based on how I handle Object Properties, do you see a way on how can I build
a TDataSet or TDataSource so I can make those properties available to data
aware controls for DevExpress or reporting tools for example?

Thank you,
Guillermo

 

Re:BO visible for data-aware controls


Quote
"Guillermo Najar-Arreola" <gna...@prodigy.net.mx> wrote in message

news:3d89f664@newsgroups.borland.com...

Quote
> Based on how I handle Object Properties, do you see a way on how can I
build
> a TDataSet or TDataSource so I can make those properties available to data
> aware controls for DevExpress or reporting tools for example?

My preference is to build a TDataset descendant that acts as a BODataset and
can act as the bridge between the UI and the BO. I have an article
(http://www.gexperts.com) on creating TDataset dscendants that has an
example showing how to create a dataset to connect to TCollection based
classes. This example is easily ported to connecting to BOs.

Another idea that Wayne likes is to have the BO expose a clientdataset and
the BO is responsible for populating and managing this clientdataset.

Gerald

Other Threads