Recent

Author Topic: TFBAdmin - How do I tell if it's already connected?  (Read 1764 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
TFBAdmin - How do I tell if it's already connected?
« on: January 01, 2018, 12:59:12 am »
Platform:  Windows Server 2016, Lazarus 1.9  Fpc 3.1.1

The TFBAdmin component doesn't have a ".Active" or ".Connected" property.  It has a private ".CheckConnected" property, but I cannot get at it, other than making my own wrapper for the TFBAdmin component which I'd rather not do. 

If I try to .Connect to the TFBAdmin component and it's already connected, it throws an error saying it's already connected.
If I try to .Disconnect to the TFBAdmin component and it's already disconnected, it throws an error saying it's already disconnected.

Am I doing this wrong?  No examples show how to test if it's disconnected or connected.  The examples just connect/disconnect as if the connection was successful, or as if it was disconnected in the first place.

balazsszekely

  • Guest
Re: TFBAdmin - How do I tell if it's already connected?
« Reply #1 on: January 01, 2018, 08:11:19 am »
Inside TFBAdmin.Connect function, instead of:
Code: Pascal  [Select][+][-]
  1.  if FSvcHandle<>FB_API_NULLHANDLE then
  2.     raise EIBDatabaseError.CreateFmt(SErrConnected,[Self.Name],nil,0,'');
should be:
Code: Pascal  [Select][+][-]
  1.  if (FSvcHandle<>FB_API_NULLHANDLE) and (FUseExceptions)  then
  2.     raise EIBDatabaseError.CreateFmt(SErrConnected,[Self.Name],nil,0,'');
Then you could change the behaviour by setting UseExceptions property to false. You should file in a bug report or even better create a patch where a new Connected property is available. All you have to do is check in the getter method if FSvcHandle<>FB_API_NULLHANDLE.
However if your time is limited, just try except the connect/disconnect function and you're good to go, like this:
Code: Pascal  [Select][+][-]
  1. uses IBConnection;
  2. //...
  3. try
  4.    FBAdmin1.Connect;
  5. except
  6.   on E: EIBDatabaseError do
  7.   begin
  8.     //already connected, do something
  9.   end;
  10. end;
Please note, this will still raise a debugger exception inside the IDE(you can choose to ignore it) however your executable will run fine outside the IDE.

 

TinyPortal © 2005-2018