Correct format specifier for printing HRESULT with Delphi 6's Format() statement in hexadecimal format?

StackOverflow https://stackoverflow.com/questions/8221505

  •  06-03-2021
  •  | 
  •  

Question

I have a Delphi 6 application that uses the DSPACK component library. That library prints a log line when in debug mode whenever a particular DirectShow operation fails. Here's the relevant souce code line:

format('Error %08lX from FillBuffer!!!', [Result])

Unfortunately this line leads to an EConvertError Exception in SysUtils.ConvertErrorFmt(). What is the correct format specifier to use when trying to print an HRESULT correctly in hexadecimal format?

Was it helpful?

Solution

The token which you are passing (%08lX) to the function is invalid, to format a value as Hexadecimal you must use the X char, and to specify the length use a dot followed by the count of desired chars like this %.8X

Check this sample

format('Error %.8X from FillBuffer!!!', [Result])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top