IB Components Overview
For normal database access, a datamodule should contain
KADao Overview
For normal database access, a datamodule should contain
KADao table components work fine, they are much faster than Interbase table components.
Basic Info
File / New... / Data Module (Delphi 5) File / New / Data Module (Delphi 6) File / New / Other... / Data Module (Delphi 6)
Creation Order
When KADaoDatabase1 is the first component added to a datamodule, it is automatically created first.
To control the creation order, from the menu, select
Edit / Creation Order...or right click the datamodule and select
Creation Order...
Webservers
Project / Add to Project...(Perhaps there is a problem with multithreading.)
The following works fine
procedure TWebModule_AB.WebModuleCreate(Sender: TObject); begin SamplesDataModule := TSamplesDataModule.create(self); end;
Applications
In general, I prefer portable code that is able to determine the appropriate path at run time - I provide an ini file for that purpose.
Inheritance
According to the help, it is possible to add datamodules to the Repository. Once that is done, then you can inherit from those and everything should be ok.
The only problem is that the instructions on adding datamodules to the repository are almost correct. They say
2. .. For a .. data module, right-click the item and choose Add To Repository.The more correct instructions
2. .. For a .. data module, make sure that the datamodule (not the code) is displayed (use F12 to toggle between the 2 displays) then right-click the datamodule and choose Add To Repository.
When creating a new datamodule (in Delphi 5), select File / New... / Data Modules and be sure to select Inherit (Copy is the default) before clicking OK.
NOTE: For Delphi 6, use File / New / Other... / Data Modules
Doing it by hand
TSamplesDataModule = class(TDataModule)
TSamplesDataModule = class(TBasicDataModule)and add the TBasicDataModule unit (*.pas file) to the uses clause
Also, you need to delete any existing components and methods that are common to both datamodules.
object SamplesDataModule: TSamplesDataModuleto
inherited SamplesDataModule: TSamplesDataModule(This is not covered in the help file)
Basic_Firebird_DataModule in '..\..\Basic_Firebird_DataModule.pas' {BasicDataModule: TDataModule},(This is required to edit the derived datamodule in the IDE, and may be required to compile the project. Without it, Delphi produces an error when the project is opened. By the way, the "comment" is NOT optional - it is used by the IDE. Without it, the IDE is not able to display the DataModule "forms" for the derived DataModules.)
Using an Existing Data Module
This example provides 2 text fields
uses Samples_Firebird_DataModule; procedure TForm1.FormCreate(Sender: TObject); begin Application.CreateForm(TSamplesDataModule, SamplesDataModule); end; procedure TForm1.Button1Click(Sender: TObject); var flag : boolean; xx : string; begin flag := SamplesDataModule.CheckBarcode(Edit2.Text); if flag then xx := 'true' else xx := 'false'; Edit1.Text := xx; end;It is also possible to use Project / Add to Project... to add the DataModules ... however, you MUST add Basic_Firebird_DataModule first and then one (or more) of the other data modules. This method adds the DataModules to the *.dpr file.
Delphi Version
// Delphi 5 example uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; // Delphi 6 example uses SysUtils, Classes;Code created in Delphi 5 compiles ok in Delphi 6, but to get Delphi 6 code to compile in Delphi 5, the Forms unit needs to be included. For instance, this example can be used to create compatible code
{$IFDEF VER130} // Delphi 5 {$DEFINE mc_LE_D5} // Less than or equal to Delphi 5 // I use "mc" to help avoid conflicts {$ENDIF} uses SysUtils, Classes, {$IFDEF mc_LE_D5} Forms, // Delphi 5 and below only {$ENDIF} other, units, go, here ; // Don't forget the semicolonIt is also possible to always include Forms, but it may produce slightly smaller code to omit it ... particularly when datamodules are also used in webmodules. Author: Robert Clemenzi - clemenzi@cpcug.org