|
|
| Combining TADQuery with TADUpdateSQL | | Posted by Diman [Aug 20, 2009] | I am often see the requests to merge the TADQuery and the TADUpdateSQL together to make a single component allowing to specify as a base SQL query, as the data editing SQL commands.
| But my answer is - no, I will not. Why it is so ? - We are a "brick plant". So, we have built AnyDAC, which is a set of "bricks", from which you can build any "building" you need. If there will be too many "bricks" of all possible sizes and characteristic, that will make confusion.
- Not many AnyDAC customers need such a mix. And the others may be confused by the one new extra component with not that sharply defined distinction from the other components.
- The good end-user approach to any DAC, including the AnyDAC, is to inherit the own data access classes from the AnyDAC components. That will allow to incapsulate into them the all required only for your application / convenient only for you functionality, like a mix of the TADQuery and the TADUpdateSQL.
- Finally ... that is very simple to implement that on your own !
So, lets cook the mix. Some of you can remember the TSimpleDataSet from the BDS 2005 and similar components. The idea is very simple, a main component creates in own constructor the required sub-components, connects them together and bingo ! In our case the TADQuery should create TADUpdateSQL and assign it to him self. Also, it will be good to prohibit to a programmer to reassign a UpdateObject property value. All that is really simple in Delphi. That is the code: uses
Classes, uADCompClient;
type
TADQueryEx = class(TADQuery)
private
FInternalUpdateObject: TADUpdateSQL;
public
constructor Create(AOwner: TComponent); override;
published
property UpdateObject: TADUpdateSQL read FInternalUpdateObject;
end;
constructor TADQueryEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FInternalUpdateObject := TADUpdateSQL.Create(Self);
FInternalUpdateObject.Name := 'InternalUpdateSQL';
FInternalUpdateObject.SetSubComponent(True);
inherited UpdateObject := FInternalUpdateObject;
end; That is all. Now you can include this class into some unit (new one ?), add the Register procedure, include the unit into some package, compile and install the component into Delphi IDE. Enjoy ! | |
|
|
|