| View previous topic :: View next topic |
| Author |
Message |
HanslH Guest
|
Posted: Mon Feb 12, 2007 3:22 pm Post subject: can't connect to interbase database before mainform creation |
|
|
Lately i've taken effort to seperate all system initilialization from
form initialization in my delphi turbo 2006 app. System init takes
place in the intialization section of the app.
I now find that init of my interbase (create component, set
transaction, set password and connect) will not function here but the
same routine doing this does function in the mainform.onshow event.
The error I get otherwise reads:
7c918fea ntdll.dll RtlpWaitForCriticalSection
7c901046 ntdll.dll RtlEnterCriticalSection
0054b54a Pveterin.exe IBSQLMonitor MonitorHook
00542953 Pveterin.exe IBDatabase TIBDatabase.DoConnect
004cfbf1 Pveterin.exe DB TCustomConnection.SetConnected
006a8dab Pveterin.exe Uveterin 8988
TDataBaseholder.CreateIBDatabase
005d8d01 Pveterin.exe UVeterinExclusive 459 InitSys
0078729e Pveterin.exe UVeterinExclusive 527 initialization
The routine:
//========================================
procedure TDatabaseholder.CreateIBDatabase;
var
IB : TIBDatabase;
i:integer;
begin
IBDatabase := TIBDatabase.create(self);
IBTransaction := TIBTransaction.create(self);
//members of tdatabaseholder class
IB := IBDatabase;
IB.connected := false;
IB.defaultdatabase := IB;
IB.defaulttransaction := IBTransaction;
IB.databasename := 'C:\Veterin\Interbase\VETERIN.GDB';
IB.loginprompt := false;
IB.Params.clear;
IB.Params.Add( 'user_name=SYSDBA');
IB.Params.Add( 'password=masterkey');
IB.Params.Add('PAGE_SIZE 4096');
IB.connected := true;
end;
//========================================
How to solve? |
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Mon Feb 12, 2007 6:51 pm Post subject: Re: can't connect to interbase database before mainform crea |
|
|
Where do you call the procedure?
Are you saying that you call it from the initialization section of some
unit?
What is TDatabaseholder?
--
Bill Todd (TeamB) |
|
| Back to top |
|
 |
HanslH Guest
|
Posted: Mon Feb 12, 2007 7:02 pm Post subject: Re: can't connect to interbase database before mainform crea |
|
|
On 12 Feb 2007 04:51:13 -0800, "Bill Todd" <no (AT) no (DOT) com> wrote:
| Quote: | Where do you call the procedure?
Are you saying that you call it from the initialization section of some
unit?
What is TDatabaseholder?
|
TDatabaseholder is just a TComponent descendent I created to make all
my database activity more surveyable and to give all
databasecomponents a parent because I specifically not want to be some
form to be the parent.
I have a special system initialization unit in which initialization
and finilazation sections take care of the start and end of my
program.
If I call the procedure somewhere there the error is present, if I put
it in the mainform.onshow event or at some menupress event all goes
well.
Initialization is divided in processes that don't need the database
yet and processes that do, so if I should be forced to iniitialize my
ibdatabase on a form I might as well drop the whole idea of
initialization and form separation. |
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Mon Feb 12, 2007 7:17 pm Post subject: Re: can't connect to interbase database before mainform crea |
|
|
HanslH wrote:
| Quote: | I have a special system initialization unit in which initialization
and finilazation sections take care of the start and end of my
program.
|
That will not work. You need to wait until the VCL has been initialized
before you create database components and connect. Use the OnCreate
event handler of the main form or data module.
--
Bill Todd (TeamB) |
|
| Back to top |
|
 |
HanslH Guest
|
Posted: Mon Feb 12, 2007 7:56 pm Post subject: Re: can't connect to interbase database before mainform crea |
|
|
On 12 Feb 2007 05:17:56 -0800, "Bill Todd" <no (AT) no (DOT) com> wrote:
| Quote: | HanslH wrote:
I have a special system initialization unit in which initialization
and finilazation sections take care of the start and end of my
program.
That will not work. You need to wait until the VCL has been initialized
before you create database components and connect. Use the OnCreate
event handler of the main form or data module.
|
No, that won't do. Not even if it's the last thing in oncreate I do,
it has to be onshow.
And it does work for other database components like tadstable.
Also I got positive feedback from a professional programmer that it is
good programming practice to seperate the visual and non visual parts
of a program. |
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Mon Feb 12, 2007 9:33 pm Post subject: Re: can't connect to interbase database before mainform crea |
|
|
HanslH wrote:
| Quote: |
No, that won't do. Not even if it's the last thing in oncreate I do,
it has to be onshow.
And it does work for other database components like tadstable.
Also I got positive feedback from a professional programmer that it is
good programming practice to seperate the visual and non visual parts
of a program.
|
Yes it is good to separate these things. However, it appears you have not
actually separated and removed the *dependencies*.
The same code you show indicates you have global variables somewhere -
IBDatabase and IBTransaction - are they part of DatabaseHolder or are they
declared elsewhere? Where is the Databaseholder class created (is it
created)? You assign this as the owner of the database components, in fact
you do not need to assign *anything* as the owner in this case. The problem
here is by assigning the owner, the VCL starts sending component messages
around before the VCL is ready.
Descend your DatabaseHolder class from TObject not TComponent - there's no
need for it it be a component.
--
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"At the apex of every great tragedy of mankind there stands the figure
of an incorruptible altruist." - Ayn Rand |
|
| Back to top |
|
 |
HanslH Guest
|
Posted: Tue Feb 13, 2007 12:26 am Post subject: Re: can't connect to interbase database before mainform crea |
|
|
On Mon, 12 Feb 2007 10:33:41 -0500, "Wayne Niddery [TeamB]"
<wniddery (AT) chaffaci (DOT) on.ca> wrote:
| Quote: | HanslH wrote:
No, that won't do. Not even if it's the last thing in oncreate I do,
it has to be onshow.
And it does work for other database components like tadstable.
Also I got positive feedback from a professional programmer that it is
good programming practice to seperate the visual and non visual parts
of a program.
Yes it is good to separate these things. However, it appears you have not
actually separated and removed the *dependencies*.
The same code you show indicates you have global variables somewhere -
IBDatabase and IBTransaction - are they part of DatabaseHolder or are they
declared elsewhere?
|
In the code is a comment indicating they are members of
TDatabaseholder.
| Quote: | Where is the Databaseholder class created (is it
created)? You assign this as the owner of the database components, in fact
you do not need to assign *anything* as the owner in this case. The problem
here is by assigning the owner, the VCL starts sending component messages
around before the VCL is ready.
|
The databaseholder is being created ever since I created my program 3
years ago as a 'holder' of all my tables. Also if I didn't create it,
I would see access violations all over the place :-)
| Quote: |
Descend your DatabaseHolder class from TObject not TComponent - there's no
need for it it be a component.
|
I do because the tables i create want either nil or a component as
owner. I'm not a OOP crack but it doesn't feel right to typecast like
this mytable := tmyadstable.create(tcomponent(self));
BUT I solved it! By just changing the name of IBDatabase. It seems I
was creating confusion between IBDatabase as my database and
IBDatabase the unit. |
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Tue Feb 13, 2007 3:23 am Post subject: Re: can't connect to interbase database before mainform crea |
|
|
HanslH wrote:
| Quote: | No, that won't do. Not even if it's the last thing in oncreate I do,
it has to be onshow.
|
Then something is wrong. I do all of my data access connection setup in
the OnCreate event handler and it has never failed.
--
Bill Todd (TeamB) |
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Tue Feb 13, 2007 4:03 am Post subject: Re: can't connect to interbase database before mainform crea |
|
|
HanslH wrote:
| Quote: |
Descend your DatabaseHolder class from TObject not TComponent -
there's no need for it it be a component.
I do because the tables i create want either nil or a component as
owner. I'm not a OOP crack but it doesn't feel right to typecast like
this mytable := tmyadstable.create(tcomponent(self));
|
No need, non-visual components like TAdsTable do not need owners, the only
reason for providing an owner is that it allows the assigned owner to take
responsibility for destroying the owned components, so when your
DatabaseHolder instance is freed, it will take down the database components
for you. However it is trvial to free these components yourself in an
overridden destructor for your DatabaseHolder class. Then you only need:
mytable := tmyadstable.create(nil);
| Quote: | BUT I solved it! By just changing the name of IBDatabase. It seems I
was creating confusion between IBDatabase as my database and
IBDatabase the unit.
|
Ah! Good stuff! <g>
--
Wayne Niddery - Winwright, Inc (www.winwright.ca)
SpaceShipOne; GovernmentZero |
|
| Back to top |
|
 |
|