0

I got into strange behavior in Delphi.

I need to apply correct logo.jpg in a runtime. So I created the list in logo.rc file and produced logo.RES file out of it.

Image1 RCDATA "Img\logo1.jpg"
Image2 RCDATA "Img\logo2.jpg"

Now, I want to display the correct image. In MyForm I pass the correct resource name:

MyStream := TResourseStream.Create(HInstance, 'Image1', RT_RCDATA);
try
 MyImage.Picture.LoadFromStream(MyStream);
finally
 MyStream.Free;

Now I want to add directive to use this newly created resource. I do that in .dpr file, just under the regular directive:

{$R *.RES}
{$R Logo.RES}

But when I run the project, I got an image that once was in use. Looks like Delphi somehow "remembers" it from somewhere and I cannot figure out where from. I don't see any references to that old file in project's options.

I tried to delete project.RES/project.dres files and recompile to let it create the file again.

I tried to delete the first directive. Then in run time I do get the proper image, but the Access violation in KernekBase.dll is thrown.

I tried even to change the name of my newly Logo.RES to the projectName.RES.

And I'm still getting the old image. I'm using Delphi 10.2.

Maybe someone has some insights on how to tackle this problem? Thank you

8
  • Add a pre-build event in the project options where you compile the .rc file to a .res file. Delphi fails on properly detect when to do this automatically! Mar 29 at 11:01
  • 1
    If you put the directive into the DPR in the form {$R Logo.RES Logo.RC } it should be properly handled by Delphi when you make a build instead of just a compile.
    – Uwe Raabe
    Mar 29 at 11:18
  • 1
    אל @DelphiCoder I compiled .rc file to a .res file using cmd brcc32 Mar 29 at 11:39
  • to @UweRaabe I tried that. If I use the syntax you wrote, it tells me that resource Image1 not found. Anfd if I do it this way {$R 'Logo.RES' 'Logo.RC' }, there is no errors but I still get the old file. Mar 29 at 11:46
  • I don't see how can I edit my question, but I discovered one more thing. If I turn off Manifest file autogenerate to none, then I get the proper file. So this is somehow connected Mar 29 at 12:06

1 Answer 1

0

Well, in the end it worked. I was playing around a lot. Looks like something with Delphi. May be it is not the perfect answer but... I'll put my way around.

I noticed that if I disable creating manifest file automatically, I do get the right image. So I created manifest file manually, basically copying what Delphi would produce by itself and tried to eliminate entries. After I eliminated assemblyIdentity I again got the proper file. When after this I enabled Delphi back to create manifest file automatically, it worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.