-5

I have a problem about Delphi source code.
Please help me explain it.

Detail problem as below:
I have two Delphi applications. They are two .dll files (it call App1 and App2). App1 has a method as below:

procedure SetImage(  objControl : Object; img: Pointer);
begin
    objControl.Picture.Bitmap := img;
end;

In App2, I call above method of App1 as below to display image on report.

SetImage(  objPreImgs, tempJPEG );

With objPreImgs is correct object and temJPEG is TJPEGImage object.

If I compile App1 and App2 with Delphi 7, there is not any problem.
If I compile App1 with Delphi 7 and App2 with Delphi 6, there is one problem (cannot display image on report).

I have not known root cause of above problem yet.
If you know, please explain for me.

p/s: App1 cannot compile with Delphi 6.

Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
  • Probably a dupe of many questions, e.g. http://stackoverflow.com/questions/15504047/tobjectlist-between-exe-and-dll-in-delphi and http://stackoverflow.com/questions/12954973/putting-classes-in-a-dl and many more – David Heffernan Aug 24 '15 at 07:05

2 Answers2

4

Despite the fact that both "apps" share a common memory area, each of them:

  • uses its own memory manager,
  • have their own VMT (virtual method table)
  • and the object model.

Thus, when you pass a pointer to an object in another "application", it considers its own and is looking for methods in own VMT. Naturally, D6 VMT differs from D7, which leads to AV, stack overflow and other errors.

So, you can`t pass objects and classes via dll | apps.

Returning to the task: you need to pass the contents of an image in a way that does not require the use of objects, for example - using iStream or SharedMemory. Also you can pass a handle to the image, because the handle is "global" value for both dll in the unified address space of the application. But...the first procedure (SetImage) is not necessary - this action must be performed in app2.

kami
  • 1,438
  • 1
  • 16
  • 23
  • @ David Heffernan, yes, but the main question was - why combination of D6&D7 doesn't work. I tried to tell that the use of objects in another dll is equivalent to the external procedure call with an incorrect parameter list. Of course, this does not negate the fact that the asker code won't compile. – kami Aug 24 '15 at 06:44
  • I see. I read "app" in the usual sense. But I see that asker has used "app" to mean DLL. Your answer is accurate then. – David Heffernan Aug 24 '15 at 06:59
0

It cant compile because it's not the correct syntax

First of all objControl : Object should be objControl : TImage img: Pointer should be img: TBitmap objControl.Picture.Bitmap := img; shoud be objControl.Picture.Bitmap.Assign(img);

I belive you need a beginners book

Jens Borrisholt
  • 6,174
  • 1
  • 33
  • 67
  • According to asker, code compiles in D7. So clearly asker has provided fake code. – David Heffernan Aug 24 '15 at 06:22
  • Thanks all. But i can compile success with Delphi 6 and Delphi 7. However, when compile App2 with Delphi 6 and run it, problem occurs. App2 still export report success, but this report is not contain image. – Nguyen Thanh Aug 24 '15 at 06:56
  • @Frank You posted fake code though. You can compile your code. But you posted different code, code that you made up for this question. Always post actual code. – David Heffernan Aug 24 '15 at 07:06
  • Hi David, actual code using component Fast Report VCL 5, so i posted it on the link: [link](https://support.fast-report.com/tickets/338913) – Nguyen Thanh Aug 24 '15 at 08:28
  • @FrankBB Posting links to external sites, especially ones that require login credentials, is among the worst things you can do. Please *edit* your question with the actual code! – Tom Brunberg Aug 24 '15 at 10:49
  • @Frank You are making a bit of a mess of this question, mainly because you haven't learnt how this site works. Please read the site help address the concerns raised. As for the issue you are trying to raise, kami and the dupes deal with that. You probably don't want to accept that message, but denial won't help. – David Heffernan Aug 24 '15 at 13:38