Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How do I use an Interbase database with standard database controls? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Database Others
Delphi 4.x
User Rating
# Votes
DSP, Administrator
Reference URL:
			Author: Kevin Howell

How do I use an Interbase database with standard database controls?


I have struggled for hours to get to grips with this. Manuals available aren't very 
clear on this. 

What you need: 

Set BDE alias for Database (BDE Administrator) 
Add table (tblDepartm) ,Datasource,Database and UpdateSQL component to a dataform. 
Set the Database field of the database to the name of the database component (Not 
to the Alias of the BDE, this is cross linked through the database component) 
Add Data aware component to main form. Set there source to Datasource above. 
Add Post button on the main form. (Set the button to post the table i.e. 
On the UpdateSQL component right click to open the SQLupdate editor. Generate the 
code for the various functions (Select, update, delete); 
Set the tables UpdateObject to the UpdateSQL component. 
Set CachedUpdates to true on the table. 

How does it work. Each table has an UpdateSQL component associated with it. This 
handles updates to a live record set. Updating a live recordset of a Interbase 
database wouldn't be possible without a UpdateSQL component. The code in the 
UpdateSQL component handles the changes to the underlying table of the table 
component. When updating a table (pressing the post button) the Onupdaterecord 
event (below) is called which then tells the UpdateSQL component which update kind 
to use (insert,delete,update). Once this is applied to the UpdateSQL component the 
changes are made to the local cached dataset. Remember these updates will not be 
applied until the Database component's Applyupdates method is called. (Below) 

Type the following into the Onupdaterecord event of the Table: 
2   procedure TDataform.tblDepartmUpdateRecord(DataSet: TDataSet;
3     UpdateKind: TUpdateKind; var UpdateAction: TUpdateAction);
4   begin
5     {This is a confusing concept, but the Apply below tells the
6     update component which SQL commands to use , insert , alter or select and
7     when you applyupdates on the database for this dataset the correct
8     sql statement is utilised and the dataset is updated. See on closequery
9     method of Department form}
10    try
11      uptDepartm.Apply(Updatekind);
12      UpdateAction := uaApplied;
13    except
14      UpdateAction := uaFail;
15    end;
17  end;

This is the code to close the main form. It checks if any updates are pending on 
the database and then applies the updates. Only now is the underlying table updated 
on the server. Keep in mind that you have to close and open the tables to reflect 
the changes on the client side because a refresh is not allowed on a DBMS like 

18  procedure TfrmDepart.FormCloseQuery(Sender: TObject;
19    var CanClose: Boolean);
20  var
21    Res: integer;
22  begin
23    with Dataform do
24      if tblDepartm.UpdatesPending then
25      begin
26        Res := messagedlg('Save changes ?', mtInformation, mbYesNoCancel, 0);
27        if Res = mrYes then
28        begin
29          dbMTS.Applyupdates([tblDepartm]);
30          {Somehow the first time you applyupdates on a dataset it is very
31          slow, but thereafter it is lightning fast. Must be that the BDE
32          only caches the info once you call the applyupdates method for the
33          first time!}
34          tblDepartm.close;
36        end;
37        Canclose := Res <> mrCancel;
38      end;
39  end;

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC