Solved

DataModules in Delphi DLLs

Posted on 2001-09-14
9
404 Views
Last Modified: 2010-04-06
I require to create a dll with a DataModule which I can use from my application and to avoid double login to a Sybase Database when the tables are opened as I have logged in initially to the database.

0
Comment
Question by:wksome
9 Comments
 
LVL 4

Accepted Solution

by:
fva earned 50 total points
ID: 6482506
You will _have_ to go for runtime packages both in your DLL and in your app. Actually, you could even make your DLL to be a runtime package itself.

Rough guideline:
For start, compile your app with runtime packages (Project/Options/Packages/Runtime checkbox). Then create a package (I would recommend using that ShareMem unit in the package _and_ in the app) and set it to compile with runtime, too. Add a datamodule to the new package.

Go back to the app, include the DM unit you created above and add the package created above to the list of runtime packages of the project. Use the DM as if it's included in the app itself. The actual code of the DM will reside in the DPL file of the new package.

Caveats:
Do not forget do distribute all the DPL's required (Delphi's and yours, too)
When auto-compiling more than 2 levels of packages all sort of weird things happen (at least in D3 - yes I'm still on D3)
The compiler gets fuzzy with optimization of embedded functions in projects using runtime pk.
...

All in one, you should accept the extra Sybase connection as a fact of life instead of going runtime pk unless you really _have_ to do this DLL stuff (e.g. if you want to implement some plug-in features)

All above opinions are based on D3 over Oracle experience. Other versions or DBMS backends might not fit my words :).

F.
0
 
LVL 4

Expert Comment

by:fva
ID: 6482513
BTW, you may copy the logged-in DB.Params from the app to the DM.DB in the DLL and log in again (i.e. if you're not concerned with the presence of multiple connections but rather with user's conveniance of not having to log in twice). In that case please DO use ShareMem in the DLL and in the app.

F.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6482611
Why does he have to go go for a runtime package? I have datamodules in DLLs and they work fine.

J.
0
 
LVL 4

Expert Comment

by:fva
ID: 6482671
Yes, but I guess you maintain a distinct connection (TDatabase and eventually TSession) in the app and in the DLL. If you try to use the same TDatabase for objects in the app and in the DLL then the problems start to appear because there are global variables (Session, Sessions, ...) that is instantiated from separate code in app and in DLL and then you get different variables for the same meaning.

The problems might not appear in some patterns of usage but they are still there and might produce unwanted effects or even errors.

F.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:wksome
ID: 6482904
I would prefer jsweby's way of using DLLs instead of packages. Does jsweby have some tips please?

0
 
LVL 4

Expert Comment

by:fva
ID: 6483116
I'm afraid that it means you'll go for a separate connection to Sybase, but I might be wrong. I'm listening.

F.
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6488657
Sorry, didn't get any emails to say this topic had been updated. FVA is right, my method unfortuntely involves a whole new connection to the database which is clearly unsuitable for your needs, sorry to get your hopes up!

J.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9308030
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept fva's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now