"I am Application developer, I use components, I don't build them."
I typically have thought well I have found another "point and click" developer who is not familiar with OOP. Since I have been at my component no candidate who has said this has been hired.
Recently I ran into an exception (outside of an Interview) a Delphi Developer who was very familiar with OOP but had still not built a component. I realized that there an artificial barrier into component development, that many might see. In a future blog postI will confront this artificial barrier head on and show how easy it is to do component development. This post is show some of the arguments of why we would want to do component development as an application developer.
In 2007 we converted our application from BDE to DBX. We had written an application that converted all TQuery components to TDbxQuery components.
The process of conversion to the 3 component model of DBX (TSqlQuery -> TProvider -> TClientDataset) was going to be error prone. It was also going to take an insane amount of time that we were not willing to spend.
So we spent a few days creating a component that looked like and behaved like TQuery but internally used the 3 Component DBX model. It was similar to TSimpleDateset but had properties and functions that matched existing TQuery functionality that we used. This allowed for a search and replace of instances of TQuery with TdbxQuery. This allowed us to complete this conversion in less time that if we had just used the built in components. Since we maintained the component we were able to expose any functionality of the 3 components model that we needed.
During this process we realized we had hundreds of TDBGrid components. So we decided to help our application for the long term. We replaced TDBGrid with TDwsGrid. Initially the code looked something like this. It basically offered nothing over TDbGrid.
TDwsGrid = class(TCustomDBGrid) published property Align; property Anchors; property BiDiMode; property BorderStyle; property Color; property Columns stored False; property Constraints; property Ctl3D; property DataSource; property DefaultDrawing; property DragCursor; property DragKind; property DragMode; property Enabled; property FixedColor; property Font; property ImeMode; property ImeName; property Options; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PopupMenu; property ReadOnly; property ShowHint; property TabOrder; property TabStop; property TitleFont; property Visible; property OnCellClick; property OnColEnter; property OnColExit; property OnColumnMoved; property OnDrawColumnCell; property OnDblClick; property OnDragDrop; property OnDragOver; property OnEditButtonClick; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseActivate; property OnMouseDown; property OnMouseEnter; property OnMouseLeave; property OnMouseMove; property OnMouseUp; property OnMouseWheel; property OnMouseWheelDown; property OnMouseWheelUp; property OnStartDock; property OnStartDrag; property OnTitleClick; end;
The other day I had a look at this component, it now does the following.
- Sorts the Grid based on Click of column Title
- Persists Column positions and sizing to a configuration file.
- Ability to Export to Excel.
It's not a huge amount functionality but it allowed us to add this to many screens without how having to place this code to do this in every place we used TDbGrid.
When explaining this to application only developer one might expect a response of. "Well why not buy a 3rd party control that does that?" My answer "We did just that, when we had the budget we purchased a TMS Subscription and now use TDBAdvGrid in many places."
But the experience previously learned still applied to 3rd party component packages. We now are in the processed of creating, our new component which now looks like this:
TdwsAdvDbGrid = class(TAdvDBGrid) end;
Allowing us to add additional functionality to TAdvDBGrid if we need it. Granted for now we don't need to add anything. But the lesson learned from the previous experience has shown the value.
This does not just apply to additional functionality, it also applies to common custom settings.
Say for example every time you use a TEdit you need to change the Font to comply with a standard
you have set. Instead of doing the tedious mistake ridden work of doing this. Instead create a TMyEdit then use that instead of TEdit.
This does not just apply to additional functionality, it also applies to common custom settings.
Say for example every time you use a TEdit you need to change the Font to comply with a standard
you have set. Instead of doing the tedious mistake ridden work of doing this. Instead create a TMyEdit then use that instead of TEdit.
interface uses SysUtils, Classes, Controls, StdCtrls; type TMyEdit = class(TEdit) public constructor Create(AOwner : TComponent); override; end; procedure Register; implementation { TMyEdit } constructor TMyEdit.Create(AOwner: TComponent); begin inherited; Font.Name := 'My Crazy Font'; end;
So basically a developer should be able to do both, application and component development. Taking the time to learn component development will only help you in your your abilities to create great applications.