4

I get the error mentioned further on error when debugging an executable in Delphi XE2 update 4 under these circumstances:

  • that depends on mqic.dll from WebShpere that is in C:\Program Files \IBM\WebSphere MQ\bin\mqic.dll and C:\Program Files\IBM\WebSphere MQ\bin is on the system path (not on the user path).
  • is being debugged with an override environment variable in the Run -> Parameters -> Debugger -> Environment Block -> User overrides
  • Including System Variables on the same property page is checked

This is the error (it's a Windows DLL load error marked "System Error").

The program can't start because mqic.dll is missing from your computer. Try reinstalling the program to fix this problem.

A few notes:

  • I debug as regular user (which is normal practice anyway, but in this case, I can't be administrator because of policies at the client).
  • As soon as I remove the environment variable, it works (but the program barfs as it really needs the info).
  • Specifying the environment variable before Delphi starts is cumbersome, but doable as a temporary workaround (I need to change that variable often while debugging to test different scenario's; the startup/shutdown times of Delphi makes this tedious).
  • I cannot do without the environment variable because it is required for an application where there is no source code for and cannot be rewritten in time for it to be phased out anyway

This is what the event log shows:

Faulting application name: CAS400NTMQ.exe, version: 1.1.4639.52512, time stamp: 0x50508180
Faulting module name: ntdll.dll, version: 6.1.7601.17725, time stamp: 0x4ec49b60
Exception code: 0xc0000005
Fault offset: 0x0005333f
Faulting process id: 0x4b20
Faulting application start time: 0x01cd90e36bb90816
Faulting application path: C:\Users\...\bin\CAS400NTMQ.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: a9853965-fcd6-11e1-ae66-78e3b5ca2514

Question: is there another solution or easier workaround than what I'm using above?

Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 1
    Well, no idea why this happens, but the easy fix is just to write a batch file (.bat) that sets the environment variable (using set) and then starts Delphi. That's the bit that you call cumbersome but a the batch file deals with that. Or an a user environment variable outside the IDE using the Windows environment variable setting dialog. Then you don't need admin rights. – David Heffernan Sep 12 '12 at 15:14
  • As an aside, you state that you can't debug as admin. It almost sounds as though it's normal practice to do so. It really isn't! – David Heffernan Sep 12 '12 at 15:25
  • You are right, it isn't (and I will emphasize that). In this case I won't be able to even if needed. – Jeroen Wiert Pluimers Sep 12 '12 at 16:05
  • "C:\Program Files\IBM\WebSphere MQ\bin is on the path" - which path, User or System ? – Arioch 'The Sep 12 '12 at 16:15
  • @Arioch'The System wide. Will edit the question. – Jeroen Wiert Pluimers Sep 12 '12 at 16:30
  • 1
    Weird, `GetEnvironmentVariable('PATH')` returns empty string while debugging, correct path otherwise. Select 'PATH' in 'system variables' and click 'add override'. Worth a try.. – Sertac Akyuz Sep 12 '12 at 16:39
  • 1
    The behavior in the previous comment can only be observed if there's an override, not if the 'user overrides' section is empty. XE and below does not seem to have a similar problem. – Sertac Akyuz Sep 12 '12 at 17:29
  • @SertacAkyuz can you make that an answer (preferably with a small console app showing the `PATH`), then I'll accept+vote it, regression the app with XE3 and QC it if needed. – Jeroen Wiert Pluimers Sep 12 '12 at 17:36

2 Answers2

6

According to Andreas Hausladen's latest blog post, and his answer here, this XE2 bug is taken care of by IDEFixPack. And is not needed in XE3 since XE3 fixes the problem.

So I suspect that may be the most effective workaround if you can manage to get IDEFixPack installed on this machine. Even if you can't get IDEFixPack installed, then this answer could still be useful to other readers.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • +1; I've done this on my local development workstation and it works great. Will try to see if I can get the IDEFixPack installed, might be doable as it didn't ask for UAC on my local development workstation. – Jeroen Wiert Pluimers Sep 13 '12 at 05:17
5

There's something wrong with Delphi XE2's processing with user overridden environment variables. Take the sample app:

program Project1;

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

begin
  Writeln(GetEnvironmentVariable('PATH'));
  Readln;
end.

This outputs the path fine when run out of the debugger, or when there's no user override environment variable. But as soon as you introduce an environment variable in Run->Parameters->Environment Block, it outputs an empty string.

A possible workaround seems to be to override the required variable, in this case 'PATH'. Then the program can output (and possibly use) the correct path again. Obviously this is a fairly limited workaround. Once you employ a user override, it's not only 'PATH' you lose. F.i. the example program still won't be able to output 'APPDATA'.

Previous Delphi versions does not seem to have this problem. There's a report on QC: Include System Variables isn't working anymore which is closed as 'fixed' in build 17.0.4625.53395.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • 4
    +1. Just as an FYI: The build number for the fix is the initial release version and build number for XE3. Also can confirm that your code produces the correct output for `PATH` when tested in XE3. – Ken White Sep 12 '12 at 18:54
  • 2
    As a note to the comment above: Confirmed both with and without a user override for `PATH` in Project->Options->Environment Block. (Edit timed out before I could add it there.) – Ken White Sep 12 '12 at 19:01
  • 2
    @Ken: I can confirm both the bug in XE2 and the fix in XE3. Build 17.0.4625 is XE3. – Rudy Velthuis Sep 12 '12 at 19:32