TSQLDBlibraryloader fails @designtime lazarus / 16-Databases ---------------------------------------------------------------------- mangakissa · 2017-11-04 13:58 I Put TSQLConnector and TSQLDBLibraryloader on form. Set property libraryname to the path of the clientlibrary. Then I set property enabled to true. If I run the application, fpc comes with the error : Quote'..raised exception class EDatabaseError with the message: SQLDBLibrayloader1: This operation is not allowed while the database is loaded. Why is this happen? property TSQLConnector.connected is still set to false. I know it can be fixed at runtime, but my demo requires this option @designtime. ---------------------------------------------------------------------- LacaK · 2017-11-06 06:39 TSQLDBLibraryLoader message is not related to TSQLConnector. Probably you have in your code: SQLDBLibrayloader1.Enbled := True; ? or any other use of SQLDBLibrayloader1 ? ---------------------------------------------------------------------- mangakissa · 2017-11-06 07:45 Yes I did. So what's the relation to TSQLConnector? I know it tells to the TSQLConnector where to find the required library. What's the purpose of the property enabled? ---------------------------------------------------------------------- mangakissa · 2017-11-06 08:38 I looked into the source by property enabled: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TSQLDBLibraryLoader.SetEnabled(AValue: Boolean);begin  if FEnabled=AValue then Exit;  if (csLoading in ComponentState) then    FEnabled:=AValue  else    If AValue then      LoadLibrary    else    UnloadLibrary;end;                      Does the clientlibrary has to be loaded before starting the connection to the database. What is TSQLconnector doing when the library already loaded? I couldn't find any code to see what happens if TSQLConnector.connected is set to true. There's also a problem with the IDE if the application is haved with TSQLDBloadlibrary.enabled := true. When the project will loaded into the IDE, the IDE goes in a loop or it will fails when loading the TSQLDBloadlibrary. ---------------------------------------------------------------------- molly · 2017-11-06 08:50 Quote from: mangakissa on November 06, 2017, 09:38:15 amI couldn't find any code to see what happens if TSQLConnector.connected is set to true. TSQLConnector inherits from TSQLConnection which in its turn inherits from TDatabase. TSQLConnection (re)publishes the property Connected so we go up one ancestor to see what that does. Code: [Select]TDataBase: property Connected: Boolean read FConnected write SetConnected; So we need to look at TDataBase.SetConnected() but alas, that one is implemented in (yet another one) its ancestor class TCustomConnection. so we take a look there: Code: [Select]procedure TCustomConnection.SetConnected(Value: boolean); begin   If Value<>Connected then     begin     If Value then       begin       if csReading in ComponentState then         begin         FStreamedConnected := true;         exit;         end       else         begin         if Assigned(BeforeConnect) then           BeforeConnect(self);         DoLoginPrompt;         DoConnect;         if Assigned(AfterConnect) then           AfterConnect(self);         end;       end     else       begin       if Assigned(BeforeDisconnect) then         BeforeDisconnect(self);       DoDisconnect;       if Assigned(AfterDisconnect) then         AfterDisconnect(self);       end;     end; end; We take a look at DoConnect, which is virtual. We see that its child TDataBase does override DoConnect and reads: Code: [Select]procedure TDatabase.DoConnect; begin   DoInternalConnect;   FConnected := True; end; So, there it calls DoInternalConnect. DoInternalConnect is overridden in the child classes. For TSQLConnector that reads: Quoteprocedure TSQLConnector.DoInternalConnect; Var   D : TConnectionDef; begin   inherited DoInternalConnect;   CheckProxy;   FProxy.CharSet:=Self.CharSet;   FProxy.DatabaseName:=Self.DatabaseName;   FProxy.HostName:=Self.HostName;   FProxy.LogEvents:=Self.LogEvents;   FProxy.Password:=Self.Password;   FProxy.Role:=Self.Role;   FProxy.UserName:=Self.UserName;   FProxy.FTransaction:=Self.Transaction;   FProxy.LogEvents:=Self.LogEvents;   FProxy.OnLog:=Self.OnLog;   FProxy.Options:=Self.Options;   D:=GetConnectionDef(ConnectorType);   D.ApplyParams(Params,FProxy);   FProxy.Connected:=True; end; Note that Inherited DoInternalConnect is executed, so look at its parent's class implementation of DoInternalConnect as well. That is, if i understood your question correctly. edit: added some additional in-between steps ---------------------------------------------------------------------- mangakissa · 2017-11-06 11:21 Part of it Molly. I tried to understand which relation TSQLDBLibraryloader has to TSQLConnector (TSQLConnection). If the libraryloader is loading the clientlibrary, what is TSQLConnector (TSQLConnection) doing with the loaded library. If this component is not available, TSQLConnector (TSQLConnection) handles the loading of the client library by itself (AFAIK). Why is loading my project failing when I use TSQLDBLibraryloader.enabled := true. It's nice to know where you can find the procedures of the handled code, but is not my purpose. Delphi and Lazarus/FPC are built to build a application in the IDE without a single code put by user. ---------------------------------------------------------------------- molly · 2017-11-06 12:08 Quote from: mangakissa on November 06, 2017, 12:21:49 pmPart of it Molly. Was already afraid you was going to say that :-D Databases are not my greatest virtue, and usually i set properties manually at runtime instead of design-time (so double my handicap  ) QuoteI tried to understand which relation TSQLDBLibraryloader has to TSQLConnector (TSQLConnection). afaik, none whatsoever other then overriding some default behaviour (in particular the path and name of the library). QuoteIf the libraryloader is loading the clientlibrary, what is TSQLConnector (TSQLConnection) doing with the loaded library. afaik the libraryloader is responsible for 'correcting' default behaviour that TSDQLConnection expresses. TSQLConnection and friends uses a default location (path) and name for the clientlibrary (.dll/.so) and this might not correspond to your (end-user)situation. Ergo Library loader let's you customize some (default) settings. QuoteIf this component is not available, TSQLConnector (TSQLConnection) handles the loading of the client library by itself (AFAIK). afaik as well, yes. QuoteWhy is loading my project failing when I use TSQLDBLibraryloader.enabled := true. No idea atm. The message you showed seem to indicate that the database/connection has already been opened ("database already loaded"). QuoteIt's nice to know where you can find the procedures of the handled code, but is not my purpose. Indeed it is not, but sometimes knowing the flow of the program is able to help you understand certain issues/topics. I assumed that is why you asked the question i quoted and replied to. QuoteDelphi and Lazarus/FPC are built to build a application in the IDE without a single code put by user. Although you as a developer do not have to code anything when visually creating a design, behind the scenes a lot of code is executed (either at design-time or at execution time) because of the (visual) changes that you've made. All the properties you've changed are stored inside the .lfm file and when you load your program (either at execution or designtime) these changes are streamed inside your program and therefor a lot of those changed properties invoke code (that you probably never knew existed before). That is why (under certain circumstances) it is advisable to build lazarus/components in debug-mode so that you are able to debug the components source-code at runtime and be able to see what the debugger has to tell. Note that afaik using libraryloader requires you to set properties in a particular order, otherwise things might go amiss (see also here). Did you follow the rules from that small example ? Also note that there are some libraryloader examples available in fpc source-tree. ---------------------------------------------------------------------- mangakissa · 2017-11-06 13:59 I'm aware of the wiki part. But AFAIK it's a kind of workaround and not the solution to the GUI part. I have to change my script, because it fails @desingtime. QuoteAlthough you as a developer do not have to code anything when visually creating a design, behind the scenes a lot of code is executed (either at design-time or at execution time) because of the (visual) changes that you've made. If a compagny gives you a vision to built something without any word of code typed, it should work. A newbie/beginner doesn't know anything about the exceptions. But know this topic is almost offtopic. I shall be carefull for my answers I hope that Lacak can explain why TSQLDBLibrary.enabled is not working as it should. ---------------------------------------------------------------------- molly · 2017-11-06 16:45 Quote from: mangakissa on November 06, 2017, 02:59:36 pmI'm aware of the wiki part. But AFAIK it's a kind of workaround and not the solution to the GUI part. Currently a bit besides the question. To make sure (as you mentioned it in your first post as well): are you able to 'get rid of' the exception when you use runtime code ? QuoteI have to change my script, because it fails @desingtime. Yes, i am aware. Please don't worry about that  QuoteA newbie/beginner doesn't know anything about the exceptions. That is a bit of a contradictio in terminis. The exceptions are (also) there to help newbies understand errors in a better way, be able to locate them inside the source so that they can be addressed. I admit, some exceptions make more sense than others. Also in this case, the error is clear. The problem lies in figuring out the 'why' part. I feel that some short example in order to reproduce the issue would be more helpful. QuoteI hope that Lacak can explain why TSQLDBLibrary.enabled is not working as it should. I'm currently blank as i seem unable to reproduce. So, any help from a more savvy user would be appreciated. ---------------------------------------------------------------------- LacaK · 2017-11-07 19:28 Quote from: mangakissa on November 06, 2017, 02:59:36 pmI hope that Lacak can explain why TSQLDBLibrary.enabled is not working as it should. I will try. First how TSQLDBLibraryLoader works was already answered I think. Simply say TSQLDBLibraryLoader loads appropriate library before any TSQLConnection tries open connection. When you look into code you will see that TSQLConnection will load library ONLY if none is already loaded. So if "somebody" loads library in advance TSQLConnection does nothing else uses already loaded library. And why it does not work for you when you set Enabled at design time? Simply say you found a bug IMO ;-) It is related to order how published properties are stored/read from LFM. When you look into LFM you will see Enabled at first place then followed by ConnectionType and  LibraryName. When component is loaded properties are set in order how they are stored in LFM. And what is happening in TSQLDBLibraryLoader.SetCType and TSQLDBLibraryLoader.SetLibraryName ... CheckDisabled is called ... I will contact author of component to confirm my suspection and will let you know ... EDIT: Fixed already in revision: 37570