Logo
Development of Delphi components and applications   

rDBTools and rDBActions - example of using

Step 0 - preparing application

  • Create new application with any type of connection to database (ADO, BDE)
  • Place TDataSet, TDataSource and rDBGrid to form and connect all together to show data in rDBGrid
  • Add columns to TDataSet and to rDBGrid (via Columns property or via design time editor)
Or download prepared application, for ADO connection here, for BDE connection here.

Step 1 - using rDBTools (without rDBActions)

  • add reference to rdbtools to uses part of form:
    uses rstring, rdlg, rtool, rdbtool, rDBFind, rDBFilter, rDBFields, rDBExport, rDBPrint, rDBGridProps, rDBFilterSaver;
  • Find dialog - place TButton and add OnClick code rDBFind.FindRec(rDBGrid1);
  • Filter dialog - place TButton and add OnClick code rDBFilter.FilterRec(rDBGrid1);
  • Filter by selection - place TButton and add OnClick code rDBFilter.FilterBySel(rDBGrid1,fjNone); and so on for another filter function (see rDBFilter.pas and rDBFilterSaver.pas for detail)
  • Fields dialog - place TButton and add OnClick code rDBFields.ChooseFields(rDBGrid1);
  • Grid properties dialog - place TButton and add OnClick code rDBGridProps.DBGridProperties(rDBGrid1,true);
  • Export dialog - place TButton and add OnClick code rDBExport.DBExport(rDBGrid1,true,true);
  • Print dialog - place TButton and add OnClick code rDBPrint.DBPrint(rDBGrid1,true,true,'Caption',nil);

Parameters of most rDBTool procedures can be DBGrid, rDBGrid or TDataSet.

Step 2 - sorting with rDBGrid

Sorting function is depended on type of connection (ADO, BDE...), so implementation is following:

Sorting with ADO connection:

  • Add reference to rdbtool_ADO to uses part of form
  • Find OnChangeSort event of rDBGrid and add code rdbtool_ADO.ChangeSortADO(DataSet as TCustomADODataSet,SortFieldName,SortDesc,Accept);

Now you can click on title of row and sorting is done. Shift+Click can be used for multi column sorting.

For changing sorting according selected field after click on some Sort button add OnClick code rDBGrid1.ChangeSort(rDBGrid1.SelectedField.FieldName,true);

Sorting with BDE connection:

  • Add reference to rdbtool_BDE to uses part of form
  • Find OnChangeSort event of rDBGrid and add code rdbtool_BDE.ChangeSortBDE(DataSet as TBDEClientDataSet,nil,SortFieldName,SortDesc,Accept);
  • if you want to keep active record after sorting, set some key field (with unique values) in place of second parameter (nil)

Now you can click on title of row and sorting is done. Sorting is working only for fields with index.

For changing sorting according selected field after click on some Sort button add OnClick code rDBGrid1.ChangeSort(rDBGrid1.SelectedField.FieldName,true);

Step 3 - using rDBAction

Preparing application for using rDBAction

  • Use Add file to project and add unit dm_rDBAction.pas from DBForm directory
  • Use Add file to project and add unit fr_DBToolbar.pas from DBForm directory
  • Use Add file to project and add unit fr_DBEditbar.pas from DBForm directory
  • Open Project-Options dialog and move rDBAction form to first position on Auto-create forms

Using rDBAction toolbars in form

  • Add reference to rDBAction to uses part of form.
  • Open OnShow (or OnActivate if you using non modal forms) event of form and add code rDBAction.SetActiveGrid(rDBGrid1);
  • Find PopupMenu property of rDBGrid1 and select value rDBAction.pmDBAction
  • Place new Frame to form and select rDBToolBar
  • Place new Frame to form and select rDBEditBar
  • Open design time editor of rDBGrid (dblclick on it) and in tab rDBAction select which action should be available for this grid
  • Run the application

Now you can use all tools and editing actions from toolbar or popup menu of Grid.

The same steps use for each form in application with DBGrid.

For using more grids in one form (e.g. with TTabControl), use only one rDBToolBar and rDBEditBar and only call rDBAction.SetActiveGrid(ActiveGrid); after changing of Tab, ActiveGrid is actually selected grid.

Note

Refresh action is depended on connection (ADO, BDE...), so implementation is following:

Refresh with ADO connection:
  • Find OnRefreshData event of rDBGrid and add code rdbtool_ADO.RequeryGridADO(rDBGrid1);
Refresh with BDE connection:
  • Find OnRefreshData event of rDBGrid and add code rdbtool_BDE.RequeryGridBDE(rDBGrid1);

Now you can click on Refresh button and data is reloaded from the database.

Using rDBAction with another buttons

In some cases is better to use TButton, TBitBtn or TSpeedButton instead of predefined toolbars. Implementation is very easy:
  • Add reference to rDBAction to uses part of form.
  • Open OnShow (or OnActivate if you using non modal forms) event of form and add code rDBAction.SetActiveGrid(rDBGrid1);
  • Place new Button, BitBtn, SpeedButton or ToolButton to form
  • Find Action property of this Button and select any action of listed rDBActions
  • Run the application


Download demo for detailed demonstration of rDBActions and rDBTools.


Back
Contact:
Tomas Rosinsky
Czech Republic
e-mail: delphi@rosinsky.cz
All products are for Microsoft Windows
Components are tested with Delphi 6,7, 2005, 2006, 2007, 2009 and 2010
Number of visitors:
Your order will be processed by:
BMT Micro