Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DataModules in Delphi DLLs

Posted on 2001-09-14
9
410 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 65
Delphi Yen format 3 45
Multi-layered image in FireMonkey 9 49
FMX TEdit KeyUp handler detecting  "enter" key 4 14
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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