Board index » delphi » IBDatabase should not save Active state in design mode

IBDatabase should not save Active state in design mode

Hi,

D5.01.IBX4.3.late.night,

Having a datamodule with an ibdatabase and an ibdataset, I see
that if I use the field editor, VCL automatically opens the database.
If I then Run, Delphi saves the project including the Active state of
the IBDatabase. Then, when the app launch, since the IBDatabase.active
is saved as True, the app comes up with IBDatabase connected.
This is sometimes rather irritating, as it takes longer to launch the app,
and since the code must deal with an already connected database.

I know that I can set active=false, thus closeing the database, but during
development work, it becomes active all the time, since I must use
the field editor all the time.

Is there a way to prevent IBX from saving the (automatically set)
Active state?

A suggestion could be to have a hidden boolean property indicating
that Active was not set by the programmer, but by the field editor.
When saving, the hidden boolean could make sure that Active := false
if Active was set by the field editor.

Thomas

 

Re:IBDatabase should not save Active state in design mode


Quote
Thomas Jensen wrote:

> Hi,

> D5.01.IBX4.3.late.night,

> Having a datamodule with an ibdatabase and an ibdataset, I see
> that if I use the field editor, VCL automatically opens the database.
> If I then Run, Delphi saves the project including the Active state of
> the IBDatabase. Then, when the app launch, since the IBDatabase.active
> is saved as True, the app comes up with IBDatabase connected.

> This is sometimes rather irritating, as it takes longer to launch the app,
> and since the code must deal with an already connected database.

This is exactly how TDatabase works.

Quote
> I know that I can set active=false, thus closeing the database, but during
> development work, it becomes active all the time, since I must use
> the field editor all the time.

The Field editor should turn it back off if it had to turn it on, saving Active
is the correct way to do things though.

Quote
> Is there a way to prevent IBX from saving the (automatically set)
> Active state?

No.

Quote
> A suggestion could be to have a hidden boolean property indicating
> that Active was not set by the programmer, but by the field editor.
> When saving, the hidden boolean could make sure that Active := false
> if Active was set by the field editor.

> Thomas

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Re:IBDatabase should not save Active state in design mode


Quote
> > I know that I can set active=false, thus closeing the database, but
during
> > development work, it becomes active all the time, since I must use
> > the field editor all the time.
> The Field editor should turn it back off if it had to turn it on, saving
Active
> is the correct way to do things though.

It is good logic that VCL saves all non-default published properties.
However, since database.connected is set to true by Delphi (field editor),
it should
also be set to false by Delphi (field editor).
It does not. Not with a BDE-database and not with a IBX-database.

I guess my complaint should be directed to the Delphi-developers...

Thomas

Re:IBDatabase should not save Active state in design mode


I actually had this problem with a TDatabase in an MS-SQL server
environment, and yes I too found it rather annoying, particularly since it
would make the application break if ran on a different server than the
development server (a problem that would sometimes slip through our
"testing" department on an emergancy quick-fix). We ended up making a
descendant of TDatabase that simply did not store in the DFM the ACTIVE
value, so it would _always_ default to False.

While this fixed the problem of us inadvertantly connecting the TDatabase
(such as through the Fields Editor), if we ever had a TQuery active, this
would automatically open the TDatabase, regardless of it's stored state...

-BKN

Quote
> Is there a way to prevent IBX from saving the (automatically set)
> Active state?

Re:IBDatabase should not save Active state in design mode


I had the same problem when I started using IBX.
I think the DatabaseName property at design time should point to the
development database.

Now I write a BeforeConnect event handler:

add  - Registry -  to the uses clause and a TOpenDialog for the very first
use of the app on a machine

procedure TdmMain.TDataBase1BeforeConnect(Sender: TObject);
var Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.Rootkey := HKEY_LOCAL_MACHINE;
//try to open the key if not found open OpenDialog1 to select a proper
database
    if not Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',False)
then
     if OpenDialog1.Execute then
      begin
        Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',True);
        Reg.WriteString('IBPath',OpenDialog1.FileName);
      end;
    IBTransaction1.Active:=False;
    TDataBase1.DatabaseName:=Reg.ReadString('IBPath');
  finally
    Reg.CloseKey;
    Reg.Free;
  end;
end;

This way your TDataBase only has to connect once during start-up and the
DatabaseName is stored outside the application: you have to connect anyway,
it always takes time to connect.
If you are working in a client/server situation, you should be able to edit
or change the filename returned by the open dialog depending on the protocol
and server type.

Re:IBDatabase should not save Active state in design mode


Actually John Kaster and I wrote a IBDatabase INI that does the same thing.
I've considered rolling it into IBX proper at some time.  

Quote
Daniel Tytens wrote:

> I had the same problem when I started using IBX.
> I think the DatabaseName property at design time should point to the
> development database.

> Now I write a BeforeConnect event handler:

> add  - Registry -  to the uses clause and a TOpenDialog for the very first
> use of the app on a machine

> procedure TdmMain.TDataBase1BeforeConnect(Sender: TObject);
> var Reg: TRegistry;
> begin
>   Reg := TRegistry.Create;
>   try
>     Reg.Rootkey := HKEY_LOCAL_MACHINE;
> //try to open the key if not found open OpenDialog1 to select a proper
> database
>     if not Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',False)
> then
>      if OpenDialog1.Execute then
>       begin
>         Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',True);
>         Reg.WriteString('IBPath',OpenDialog1.FileName);
>       end;
>     IBTransaction1.Active:=False;
>     TDataBase1.DatabaseName:=Reg.ReadString('IBPath');
>   finally
>     Reg.CloseKey;
>     Reg.Free;
>   end;
> end;

> This way your TDataBase only has to connect once during start-up and the
> DatabaseName is stored outside the application: you have to connect anyway,
> it always takes time to connect.
> If you are working in a client/server situation, you should be able to edit
> or change the filename returned by the open dialog depending on the protocol
> and server type.

--
Jeff Overcash (TeamB)
      (Please do not email me directly unless  asked. Thank You)
The fool escaped from paradise will look over his shoulder and cry
Sit and chew on daffodils and struggle to answer why?
As you grow up and leave the playground
Where you kissed your Prince and found your frog
Remember the jester that showed you tears, the script for tears. (Fish)

Re:IBDatabase should not save Active state in design mode


Hi,

The below-mentioned piece of code is nice, but it is an unwanted hack.
Using the super-duper RAD-IDE-FAST-MODERN app "Delphi", I'd
prefer this annoyance be solved by a somewhat more object-oriented way,
ehh, I mean, like, that the components simply did not project this problem
onto me, the user (developer).

This said, I want to say that I can work with IBX just fine. It's simply a
great
thing!

Back to the code below, it is against my belief to have a library do
something
at startup that I don't need, like opening a database connection.
In my case, I simply want to open the connection at a later moment, not
at startup. So everytime I forget to set connected=false using the mouse,
I get this startup penalty, plus some small unimportant code problems.

Back to the field editor, it is probably the cause for my complaint, as it
is the code that needs to connect (when retrieving the metadata), and it
does not disconnect when done.
It can be compared to a problem my car once had: turning on the blinker
caused the wipers to start wiping! It was a busted fuse. Where are the fuses
in db.pas ?

Thomas

Quote
> procedure TdmMain.TDataBase1BeforeConnect(Sender: TObject);
> var Reg: TRegistry;
> begin
>   Reg := TRegistry.Create;
>   try
>     Reg.Rootkey := HKEY_LOCAL_MACHINE;
> //try to open the key if not found open OpenDialog1 to select a proper
> database
>     if not Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',False)
> then
>      if OpenDialog1.Execute then
>       begin
>         Reg.OpenKey('\Software\Borland\Borland Shared\DataPath',True);
>         Reg.WriteString('IBPath',OpenDialog1.FileName);
>       end;
>     IBTransaction1.Active:=False;
>     TDataBase1.DatabaseName:=Reg.ReadString('IBPath');
>   finally
>     Reg.CloseKey;
>     Reg.Free;
>   end;
> end;

> This way your TDataBase only has to connect once during start-up and the
> DatabaseName is stored outside the application: you have to connect
anyway,
> it always takes time to connect.
> If you are working in a client/server situation, you should be able to
edit
> or change the filename returned by the open dialog depending on the
protocol
> and server type.

Re:IBDatabase should not save Active state in design mode


My reply was an answer to BK Nielsen 's posting-situation, your problem has
been answered by Jeff Overcash.

Other Threads