Board index » delphi » Accessing a database from a DLL

Accessing a database from a DLL

Hi.

I trying to see if there is a way to access a database while in a DLL.  The
database connection as well as the query will have to be created at runtime.
Is there anyway that this can be done?

Thanks.

 

Re:Accessing a database from a DLL


You can place the database and query components on a form. Then create the
form in your dll.
application.createform(tMyForm,MyForm);

MyForm.MyDatbase.Connected := True;
..
..
..
MyForm.MyDatbase.Connected := False;

Mike Evans

Quote
Chuck M. <Bullsfa...@prodigy.net> wrote in message

news:8lkpvd$13e1@bornews.borland.com...
Quote
> Hi.

> I trying to see if there is a way to access a database while in a DLL.
The
> database connection as well as the query will have to be created at
runtime.
> Is there anyway that this can be done?

> Thanks.

Re:Accessing a database from a DLL


Quote
On Tue, 25 Jul 2000 15:38:39 -0500, "Mike Evans" <p...@mcs.net> wrote:
>You can place the database and query components on a form. Then create the
>form in your dll.
>application.createform(tMyForm,MyForm);

[Snip]

Absolutely, or a data module - or if you're feeling {*word*37}ic you
can dispense with the forms and simply create the database and query
components in some sort of initialisation routine (either executed
when the DLL is loaded, or explicitly at the request of a developer
using the DLL). In the latter case, simply set the owner to nil :

DB := TDatabase.Create(nil);
{Set TDatabase object's properties}
Query := TQuery.Create(nil);
Query.DatabaseName := DB.DatabaseName;
{Set TQuery object's properties}

Just make sure you clean them up in some sort of finalisation routine
(again, maybe executed before the DLL get's unloaded or explicitly) :

with DB do if Connected then Close;
Query.Free;
DB.Free;

I've recently done this in a DLL used for authorisation in a system
I've been developing - the connection and disconnection routines are
called explicitly and everything works very nicely...

Only one thing that might be worth pointing out. If your application
uses a TDatabase object, and a DLL it's using _also_ uses a TDatabase
object then obviously the DatabaseName property must be unique for
both of them (I say obviously, but I managed to forget this! :)

HTH, Dave.
--
Dave Hughes
EMail : d...@waveform.f9.co.uk

Other Threads