In my Delphi XE2 32-bit application (Update 4 Hotfix 1 Version 16.0.4504.48759) , I'm using the Format() routine to log pointer values.
For example:
Format('MyObject (%p)', [Pointer(MyObject)]);
However, the resulting string sometimes contains garbage characters (e.g., in this case '?' or '|' in place of hex digits):
MyObject (4E?|2010)
I also get the same result when replacing '%p' with '%x' like so:
Format('MyObject (%x)', [Integer(MyObject)]);
However, using an integer value always works:
Format('MyObject (%d)', [Integer(MyObject)]);
MyObject (1291453120)
Is there a bug that I'm unaware of or can this be related to the problem experienced here?
Why does Format crash when anything but "%s" is used with a Variant?
UPDATE
I've accepted Jeroen's answer as it led me to the solution by process of elimination. After the situation with starting the app via F7 (as per the comment), I figured that something must be going wrong much earlier in the process. On a hunch, I disabled madExcept from its IDE menu, rebuilt the app, and the problem disappeared. Evidently, whatever code madExcept was linking into my application was causing an overwrite in the SysUtils constant TwoHexLookup. Re-enabling madExcept and rebuilding (without any other changes on my part) also worked, so there must have been some corruption during the linking phase.
The strategy Jeroen outlined for detecting memory corruption was a useful exercise and should prove valuable if I encounter a similar situation.