Question

I use Delphi RAD Studio 2010 and DecimalRounding_JH1.pas from http://cc.embarcadero.com/item/21909.

It works good, but I don't know why, in some old machines (Pentium IV with Windows XP SP3), the round fails after access to printer.printerindex. I have checked that the problem not is Windows XP due it works in other machines with this OS.

I have made a simple project that round an extended value with DecimalRounding_JH1 (drHalfUp) with two decimals (1.105 -> rounds to 1.11). But If I read printer.printerindex, then 1.105 rounds to 1.10).

I thought it could be the "FDIV bug", but compiling with "FDIV safe" doesn't resolve the problem.

The code:

var d1,d2:extended;
    i:integer;
begin
     d1:=1.105;
     d2:=DecimalRounding_JH1.DecimalRoundExt(d1,2,drHalfUp);
     memo1.lines.add(FloatToStr(d2));   // --> shows 1.11 (OK)
     i:=Printer.printerindex;
     d2:=DecimalRounding_JH1.DecimalRoundExt(d1,2,drHalfUp);
     memo1.lines.add(FloatToStr(d2));   // --> shows 1.10 (ERROR!!!)
     ...

I know that it is very strange, but I've tested it and It's as I said. What could I do?

Edited: If I add Printer.printerindex:=1; (for example) before i:=Printer.printerindex; then again it works good. Reading printer unit, the difference is about execute "SetToDefaultPrinter" or not:

function TPrinter.GetPrinterIndex: Integer;
begin
  if FPrinterIndex = -1 then SetToDefaultPrinter;
  Result := FPrinterIndex;
end;

thanks in advance.

Was it helpful?

Solution

Certain parts of the system printer libraries have a rather nasty habit of modifying the 8087 control word. You should restore it to its default value after using methods and properties of Printer.

For example, you might write it like this:

Set8087CW(Default8087CW);

The comments in my codebase suggest that you only need to do this after the VCL printer code has been initialized for the first time. So you could deal with this in your program's startup. Read Printer.PrinterIndex and then immediately set the control word to its desired value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top