Hallo All you DelphiKnigths.
I'm Looking for good simple way to share from my EXE base Zeos database connection to my DLL
NO Fastmem or so . basic call only, like pointers
In my Exe ther is a datamodule ond ther is ZConnection ZEOS (version 7.0.5)
I like to uses same connection from inside the DLL
Exsalmple:
function DosomethingDBlike(count:integer;DBCON:pointer):boolean;
Can one of you DelphiKnigths help me with small exsample how to do (exe & dll)
Ps. i put this also on : Embarcadero Discussion Forums » Delphi » Database » General
https://forums.embarcadero.com/thread.j ... 4&tstart=0
Thanks Eric
simple way to share my EXE database connectio 2 DLL
-
- Fresh Boarder
- Posts: 3
- Joined: 20.09.2012, 14:50
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: simple way to share my EXE database connectio 2 DLL
Hello Eric,
Things would be more easy, if you would share some more information on what you want to do. Do you want to sell some plugings to your code or do you want to create a universal plugin architecture for your program? Which database do you use? There are some things, I can suggest, but I am not 100% sure about these things. They may be wrong.
If your DLL is not written in Delphi but in an other language, the only thing you can do is try to get the basic information needed for you specific database. Like a connection handle or connection Interface. For this to work you will have to get the IZConnection interface from the TZConnetion you use in your exe, cast that one to your database specific IZConnection interface and query that interface for the things you need. For example somjething like this:
(TZConnection.IZConnection as IZInterbase6Connection).GetDBHandle
This handle could be passed around and also be used by the DLL.
If your DLL is made in Delphi, there might be another solution: The DBC layer of Zeos is made of a lot of interfaces. So if you find a way to let a ZConnection use the same IZConnection interface, that is already used by an existing Connection, this might be a way to go. Most probably you will have to implement a new kind of TZConnection, that doesn't get the IZConnection from the Driver interface but uses one given to it from the outside. From there I think you should be on the safe side. But this will require a common memory manager, I think, as these interfaces do use the the Delphi string type a lot.
In both cases you should take care of thread safety - either on the database driver level or on the Zeos level.
And again the disclaimer: This is a lot of guesswork, so I might be wrong with some or all of my assumptions.
Best regards,
Jan
Things would be more easy, if you would share some more information on what you want to do. Do you want to sell some plugings to your code or do you want to create a universal plugin architecture for your program? Which database do you use? There are some things, I can suggest, but I am not 100% sure about these things. They may be wrong.
If your DLL is not written in Delphi but in an other language, the only thing you can do is try to get the basic information needed for you specific database. Like a connection handle or connection Interface. For this to work you will have to get the IZConnection interface from the TZConnetion you use in your exe, cast that one to your database specific IZConnection interface and query that interface for the things you need. For example somjething like this:
(TZConnection.IZConnection as IZInterbase6Connection).GetDBHandle
This handle could be passed around and also be used by the DLL.
If your DLL is made in Delphi, there might be another solution: The DBC layer of Zeos is made of a lot of interfaces. So if you find a way to let a ZConnection use the same IZConnection interface, that is already used by an existing Connection, this might be a way to go. Most probably you will have to implement a new kind of TZConnection, that doesn't get the IZConnection from the Driver interface but uses one given to it from the outside. From there I think you should be on the safe side. But this will require a common memory manager, I think, as these interfaces do use the the Delphi string type a lot.
In both cases you should take care of thread safety - either on the database driver level or on the Zeos level.
And again the disclaimer: This is a lot of guesswork, so I might be wrong with some or all of my assumptions.
Best regards,
Jan
-
- Fresh Boarder
- Posts: 3
- Joined: 20.09.2012, 14:50
Re: simple way to share my EXE database connectio 2 DLL
Thanks Jan for your quick reply.
You ask whatt i want to do :
I have basic app (exe) and make plug-in for that app
EXE have a database module wher the database is set and connected
DLL Most connect to the same database as EXE Because that is not allways same database
Type of database our MySQL & SQLLite (this have to do apps type Local or server Type)
By The way if uses a "memory manager" in exe and dll don't need any of this because you can share the Zconnection direct from exe to dll (it work for lower version of zeos)
I don't want the overhead from a "memory manager"
THanks for any reply
You ask whatt i want to do :
I have basic app (exe) and make plug-in for that app
EXE have a database module wher the database is set and connected
DLL Most connect to the same database as EXE Because that is not allways same database
Type of database our MySQL & SQLLite (this have to do apps type Local or server Type)
By The way if uses a "memory manager" in exe and dll don't need any of this because you can share the Zconnection direct from exe to dll (it work for lower version of zeos)
I don't want the overhead from a "memory manager"
THanks for any reply
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: simple way to share my EXE database connectio 2 DLL
Hello Eric,
well - a shared memory manager between the exe and the DLL is no overhead. Even more so it is beneficial. This is because each Delphi application has a memory manager built in and if you don't take precautions - a shared memory manager - every DLL has its own memory manager too. So having a shared memory manager is no overhead. Most probably the oposite is true because with a shared memory manager, the memory manager needs to be initialized only once and it needs to do the manage the memory only once.
Remember - a DLL is more or less an execuable that just happens to use the same address space as your main program.
Sharing the ZConnection directly from the EXE to the DLL most probably is adventurous at best. This is because the EXE and the DLL each have their own copy of the VCL and other components. The results are not predictable at all. This is the reason why Borland invented Delphi Packages. If you want to share your ZConnection to a plugin, it might be best for you to read about runtime loading of packages. If this is not an option for you, go back to my first post
Best regards,
Jan
well - a shared memory manager between the exe and the DLL is no overhead. Even more so it is beneficial. This is because each Delphi application has a memory manager built in and if you don't take precautions - a shared memory manager - every DLL has its own memory manager too. So having a shared memory manager is no overhead. Most probably the oposite is true because with a shared memory manager, the memory manager needs to be initialized only once and it needs to do the manage the memory only once.
Remember - a DLL is more or less an execuable that just happens to use the same address space as your main program.
Sharing the ZConnection directly from the EXE to the DLL most probably is adventurous at best. This is because the EXE and the DLL each have their own copy of the VCL and other components. The results are not predictable at all. This is the reason why Borland invented Delphi Packages. If you want to share your ZConnection to a plugin, it might be best for you to read about runtime loading of packages. If this is not an option for you, go back to my first post
Best regards,
Jan
-
- Fresh Boarder
- Posts: 3
- Joined: 20.09.2012, 14:50
Re: simple way to share my EXE database connectio 2 DLL
Thanks jan
i whass looking if ther whass a way befor i go redesign my software
i use befor a memory manager and i think it will uses it in the future to
so now go and look if and double fuctions or procedures in the old versions pfff big job
greeting eric
ps. i will close this topic
i whass looking if ther whass a way befor i go redesign my software
i use befor a memory manager and i think it will uses it in the future to
so now go and look if and double fuctions or procedures in the old versions pfff big job
greeting eric
ps. i will close this topic
Re: simple way to share my EXE database connectio 2 DLL
It can enter the connection identifier
IZPostgreSQLConnection = interface (IZConnection)
['{8E62EA93-5A49-4F20-928A-0EA44ABCE5DB}']
...
function GetConnectionHandle: PZPostgreSQLConnect;
and it was possible to have a seperate from DB layer exe dll and operates on the same connection identifier.
SetConnectionHandle function (handle: PZPostgreSQLConnect);
And what if the dll is written in Visual Studio, maybe it's not practical and passe, but I do not want to impose restrictions BPL as exe and dll must be in the same version.
IZPostgreSQLConnection = interface (IZConnection)
['{8E62EA93-5A49-4F20-928A-0EA44ABCE5DB}']
...
function GetConnectionHandle: PZPostgreSQLConnect;
and it was possible to have a seperate from DB layer exe dll and operates on the same connection identifier.
SetConnectionHandle function (handle: PZPostgreSQLConnect);
And what if the dll is written in Visual Studio, maybe it's not practical and passe, but I do not want to impose restrictions BPL as exe and dll must be in the same version.