Delphi Richedit Print

244 Views Asked by At

Please Help me. I have this Delphi code.(Delphi 11.1) ShowMessage shows me 62. On the printed paper I see this:

XT is the band founded by Kristofer Steen, David Sandström,

from all lines in the RichEdit.

TEXT is the band founded by Kristofer Steen, David Sandström, Fredrik Bäckström and Jon F Brännström. All, except Bäckström, were ex-members of hardcore band Refused.[1] Stylistically, they have little in common with Refused. Their debut album, Text, is a mix of spoken word, music of various styles, and ambient sound effects, often producing an ethereal, avant-garde sound

But I have fmtRange.chrg.cpMin := 2; fmtRange.chrg.cpMax := 5; I have to get 4 characters. What is wrong here?

procedure TForm1.Button8Click(Sender: TObject);
Var
  printarea: Trect;
  richedit_outputarea: TRect;
  printresX, printresY: Integer;
  fmtRange: TFormatRange;
  nextChar : Integer;
Begin
  Printer.beginDoc;
  richedit1.Perform( EM_FORMATRANGE, 0, 0);
  try
    With Printer.Canvas Do
    Begin
      printresX := GetDeviceCaps( handle, LOGPIXELSX );
      printresY := GetDeviceCaps( handle, LOGPIXELSY );
      printarea := Rect( printresX,            // 1 inch left margin
                         printresY * 3 div 2,  // 1.5 inch top margin
                         Printer.PageWidth - printresX, // 1 inch right margin
                         Printer.PageHeight - printresY * 3 div 2 // 1.5 inch bottom margin
                       );
      richedit_outputarea := Rect( printarea.left * 1440 div printresX,
                                   printarea.top * 1440 div printresY,
                                   printarea.right * 1440 div printresX,
                                   printarea.bottom* 1440 div printresY );
      fmtRange.hDC := Handle;
      fmtRange.hdcTarget := fmtRange.hDC;
      fmtRange.rc := richedit_outputarea;
      fmtRange.rcPage := Rect( 0, 0,
                               Printer.PageWidth * 1440 div printresX,
                               Printer.PageHeight * 1440 div printresY );
      fmtRange.chrg.cpMin := 2;
      fmtRange.chrg.cpMax := 5;
      nextChar := richedit1.Perform( EM_FORMATRANGE, longint(1), longint(@fmtRange));
      showmessage(nextChar.ToString);
      richedit1.Perform( EM_FORMATRANGE, 0, 0);
    End;
  finally
    Printer.EndDoc;
  end;
end;
0

There are 0 best solutions below