Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DataModules in Delphi DLLs

Posted on 2001-09-14
9
Medium Priority
?
425 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
[X]
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
9 Comments
 
LVL 4

Accepted Solution

by:
fva earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

721 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