Solved

DLL + APP different Delphi versions

Posted on 2000-03-15
6
357 Views
Last Modified: 2010-04-04
I have an application that loads DLLs it can find (after checking they are the right type...). Both app and DLLs are developed by myself. The app passes the Application variable to the DLLs and receives a reference to an object created by the DLL. The app e.g. calls methods of these objects. I build with run-time packages and have ShareMem as the first 'used' unit in the .dpr files. This was all done in Delphi 4

All went fine so far. Now I try to develop a new DLL, but in Delphi 5 this time. I get some weird problems in the main app, like for loops going beyond the upper bound.

Is this what I have to expect when using this approach and combining a Delphi 4 app with DLLs built in a different Delphi version? And how about DLLs built in C++ Builder?

If so, what do I have to change to make it work for different versions of app and DLL? I can not simply rebuild every time a new DLL is developed, since they may come from many different persons (and companies)

Wim
0
Comment
Question by:cadenza
6 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2620006
Some things changed in the alignment of record fields. I don't know if you exchange records between the main app and DLL's.....
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2621245
Can you show us some code snippets?

Cheers,

Raymond.
0
 

Expert Comment

by:westy100697
ID: 2622256
Have you tried turning the Optimization Directive off or

 {$O-}


WESTY :)

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Madshi
ID: 2622484
The main problem I see is the application object. It may be different in D4 and D5. So if you give in the D5 application instance to the D4 DLL, and the D4 DLL tries to access this application instance as it was a D4 application instance, you might get into serious trouble.
Is there no other way than passing the application instance to the DLLs?

If you want to go the other way (passing objects from the DLL to the application) you can run into the same problems, depending on which objects you're passing. Which kind of objects do you pass from the DLL to the app? Self declared objects? Or VCL objects? The most secure way would probably be to pass interfaces. They are guaranteed to stay the same forever, since that is what is used in COM, too. Look at TInterfacedObject and the keyword "interface", if you're interested in that.

ShareMem should work alright for D4 and D5. BTW, you know that you have to ship this borlndmm.dll (or how the name was) with your application when using ShareMem, don't you? I can give you a "magic" ShareMem unit (written by myself) with which you don't need that borland dll. Interested?

Regards, Madshi.
0
 

Author Comment

by:cadenza
ID: 2622799
Epsylon:
I know. I turned alignment on in all cases. Does not help, though.

Raymond:
this would be quite a lot, since app and dll interact quite a bit. I'll try to isolate the essential code that still has this problem. Since this will take a lot of time, I was hoping someone would be able to tell from the info I already gave what I am trying is bound to fail or should work.

Westy:
optimisation is off for app and dll

Madshi:
what you are saying is: don't pass VCL objects between app and dll, since they may be version dependant. This is the answer I feared most :0)
if you only pass self declared objects, it should be alright, isn't it? Safe also are handles, like DC handles, I guess.
I'll have a look at interfaces again. I did so before and thought I'd better avoid them if I can, since it adds complexity. Does COM slow down execution? I mean: data marshalling will be slow, I guess.
Yes, I am interested in your magic unit. Can it be shared across versions? Thanks a bunch! My email address is: cadenza@worldonline.nl

Thanks all for your replies so far. I am going to sit in a corner and think things over.

Wim
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
ID: 2622851
>> what you are saying is: don't pass VCL objects between app and dll, since they may be version dependant. This is the answer I feared most :0)

I'm sorry, but I think it's this way.

>> if you only pass self declared objects, it should be alright, isn't it?

It should be, except if Borland changes the object structure somehow. That's why I'm using interfaces for such purposes.

>> Safe also are handles, like DC handles, I guess.

Yes, they're 100% safe.

>> I'll have a look at interfaces again. I did so before and thought I'd better avoid them if I can, since it adds complexity.

Yes, but not too much. And they have several advantages, too. Like reference counting, automatic deallocation and such stuff.

>> Does COM slow down execution? I mean: data marshalling will be slow, I guess.

Well, you don't need to use full COM. Delphi interfaces are a subset of COM. If you're only using interfaces (and not full COM) you should have no big timing disadvantages. The big timing difference is, that you can't make properties like this:

  property AField : integer read FAField write FAField;

You always MUST use get and set functions. But that's all about timing, I think.

Regards, Madshi.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 91
Create a path if not exists 7 105
Broadcast a message using ICS 2 20
Firemonkey how to swip panel with finger tap 1 18
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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