Page 1 of 1

[patch_done] Add a extra Library / Path for search.

Posted: 17.04.2012, 16:26
by mmvisual
Hello,

Sometimes, I want add a extra DLL path + File for working.

Now, there is in the PlainDriver a Funktion:
FLoader := TZNativeLibraryLoader.Create([]);
{$IFNDEF UNIX}
FLoader.AddLocation(WINDOWS_DLL_LOCATION);
{$ELSE}
FLoader.AddLocation(LINUX_DLL_LOCATION);
{$ENDIF}

for adding a DLL. Now, I want install other DLL's, like "SQLite3-64.dll" and for this, I must alter the Zeos component sources.
I have looking about TZConnection, but never found a function where I can adding a extra search path/DLL into the FLoader.

It's not a bug, it's a feature.

Thank you very much for including, regards Markus

PS: Now, I use the ZeosV7 SVN1159 from here:
https://zeoslib.svn.sourceforge.net/svn ... gonhugeist

Posted: 17.04.2012, 18:17
by EgonHugeist
mmvisual,

you're right here. That's a missing thing. You're not the first who is asking for that feature. My ugly workaround: declare the WINDOWS/LINUX_DLL_LOCATION as global var. Then you can change the pathname directly from your application before you connect.

But this isn't a nice well formed solution. Having a property would be really very fine. Waiting for somebody who can patch a more elegant solution then my dirty code proposal.

Thank you for using my branch,

Michael

Posted: 26.04.2012, 00:11
by mdaems
mmvisual,

Michael already added a new functionality to testing branch to do exactly what you need.
It's not an ideal solution, but it does what you need.
As this feature isn't really ready, I'm not going to explain you how it works. If you can find out what happens in SVN rev. 1183/1184, then you're ready to use it.
If you want to know what the open issues are, please contact me (email) or michael, then we can send you a description of our thoughts. Also : don't hesitate to ask commit rights when you want to apply some patches. (The only thing we need to know is your sourceforge username)
And this is really a well defined job where you can be helpfull implementing the right solution.

Mark

Posted: 26.04.2012, 15:29
by mmvisual
Hello Mark,

Thank you very much.
Michael have exactly do it and it works very nice.

Here is my Code:

Code: Select all

function LoadLibTest(s: String): Boolean;
Var h: THandle;
Begin
  {$ifdef LINUX}
    h := dynlibs.LoadLibrary(PAnsiChar(s));
  {$else}
    h := LoadLibrary(PChar(s));
  {$endif}
  If (h <> 0)
    {$ifndef LINUX}
    And (h <> INVALID_HANDLE_VALUE)
    {$endif}
    Then
  Begin
    {$ifdef LINUX}
    dynlibs.FreeLibrary(h);
    {$else}
    CloseHandle(h);
    {$endif}
    Result := True;
  end Else Result := False;
end; 

procedure TfrmMain.DBBeforeConnect(Sender: TObject);
{$ifdef win64}
Var s: String;
{$endif}
{$ifdef linux}
Var s: String;
    i: Integer;
{$endif}
begin
  If Not(Sender Is TZConnection) Then Exit;
  If TZConnection(Sender).LibraryLocation = '' Then
  Begin // Nur suchen wenn leer
    {$ifdef win64}
    s := TZConnection(Sender).Protocol;
    If Pos('sqlite', s) = 1 Then
    Begin
      If LoadLibTest('sqlite3-64.dll') Then
        TZConnection(Sender).LibraryLocation := 'sqlite3-64.dll';
    End Else
    If Pos('mysql', s) = 1 Then
    Begin
      If LoadLibTest('libmysql-64.dll') Then
        TZConnection(Sender).LibraryLocation := 'libmysql-64.dll';
    End;
    {$endif}
    {$ifdef linux}
    s := TZConnection(Sender).Protocol;
    TZConnection(Sender).LibraryLocation := '';
    If Pos('sqlite', s) = 1 Then
    Begin
      If LoadLibTest('libsqlite3.so.0') Then
        TZConnection(Sender).LibraryLocation := 'libsqlite3.so.0';
    End Else
    If Pos('mysql', s) = 1 Then
    Begin
      For i := 30 DownTo 15 Do
      Begin
        If LoadLibTest('libmysqlclient.so.' + IntToStr(i)) Then
        Begin
          TZConnection(Sender).LibraryLocation := 'libmysqlclient.so.' + IntToStr(i);
          Break;
        End;
      End;
    End;
    {$endif}
  end;
end; 
This Code compile something for Windows64 / Linux and checkt the DLL.
If not exists the right Version, then it open the Zeos standard libraries.
I use in my form 4 TZConnection and all TZConnection use this code.

I cannot alter the code from Zeos, this code is too difficult and when I change something, I think there comes more errors inside.
I mail this changes to Michael an he can see and correct it into the right place.

I'm a tester for the Zeos component, and I will make a stable release and I load/test the testing-egonhugeist. My application is very big and is good for testing. (Google >> EleLa :-)

Now, I think Zeos 7 can going into Beta, there are very low mistakes inside.

Markus