Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

Calculating pixels when no printer installed

edited April 2003 in Devices
I am having to update the following code so that it does NOT reference a printer, since it is likely that the machine that generates the report (a server) does not have a printer installed on it. The code doesn't have comments, so to tell you the truth, I don't know for sure why it is doing what it is doing.... Maybe you can tell me :)

function WidthInScreenPixels(aString: string; aFont: TFont): Integer;
begin
ppPrintr.ppPrinter.Canvas.Font := aFont;
Result := ppPrintr.ppPrinter.Canvas.TextWidth(aString);
Result := ppUtils.ppToMMThousandths(Result, utPrinterPixels, pprtHorizontal, ppPrintr.ppPrinter);
Result := Trunc(ppUtils.ppFromMMThousandths(Result, utScreenPixels, pprtHorizontal, ppPrintr.ppPrinter));
end;

The code using this function is moving components around in the report based on a pre-specified output indicator (FPass), as follows:

procedure TfrmGenRpt.ghbAccountsBeforePrint(Sender: TObject);
begin
// Format the account information. Fields are autosized, so only set the left
if pprReport.FirstPass or (FPass = spOutsource) then Exit;

lbAcctDiv.spLeft := txtAcctNo.spLeft + ppWidthInScreenPixels(txtAcctNo.Text, txtAcctNo.Font) + 3;
txtAcctName.spLeft := lbAcctDiv.spLeft + ppWidthInScreenPixels(lbAcctDiv.Caption, lbAcctDiv.Font) + 3;
//...etc
end;

Anyhow, the problem is that, since a printer is not installed on the server, whenever the ppPrinter object is referenced, an access violation is being thrown. Is there a better way to do this?

Brandon
--
"In the beginning the universe was created. This has made a lot of people very angry, and has been widely regarded as a bad move." - Douglas Noel Adams (1952-2001)
[Please remove "nospam_" from email address to reply.]

Comments

  • edited April 2003
    Hi Brandon Lilly,

    no way, there must be a printer installed and it must be the printer used for printing.

    regards,
    Chris Ueberall;
  • edited April 2003
    "Chris Ueberall [TeamDM]" wrote in message news:3e8ae0a8@dm500....

    So the Server edition doesn't work if there is not a server installed on the server where reports are being generated?

    Brandon
    --
    "In the beginning the universe was created. This has made a lot of people very angry, and has been widely regarded as a bad move." - Douglas Noel Adams (1952-2001)
    [Please remove "nospam_" from email address to reply.]
This discussion has been closed.