Solved

DataModules in Delphi DLLs

Posted on 2001-09-14
9
408 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

808 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