Board index » delphi » Printing a TMemoField

Printing a TMemoField

In article <32641AF2.7...@pixie.co.za>, Anglo Dutch
<anglodu...@pixie.co.za> writes

Quote
>Hi

>I'm experiencing huge difficulties when I try to manually print memo
>fields to the printer canvas.
>  Are there any easy ways to print Paradox memo fields to the
>Printer.Canvas that I am evidently unaware of?

>Thanks
>Richard
>mailto:quif...@pixie.co.za

Richard,

You just have to use the Lines property and print one line at a time
For example

var
  x, y, LineHeight: Integer;  

...

    for lineno := 0 to  MyMemo.Lines.Count - 1 do
      begin
        Printer.Canvas.TextOut(x,y,MyMemo.Lines[lineno]);
        inc(y,LineHeight);
      end
--
Tim Stannard -  Ad Hoc Computing, Addlestone, Surrey, UK
                Tel/Fax: 01932 830572  Mob: 0589 918184
                e-mail: stann...@adhoc.demon.co.uk

 

Re:Printing a TMemoField


Tim,

What if line[lineno] is wider than the line width? It chops of the rest
of the line.

Regards,

Sibel Unalmis

Re:Printing a TMemoField


Quote
Haldun Unalmis wrote:

> Tim,

> What if line[lineno] is wider than the line width? It chops of the rest
> of the line.

> Regards,

> Sibel Unalmis

You will have to use the Windows API function "DrawText". It will
wrap the line if it goes beyond the boundaries.

Here is a sample code:

var
        ThisRect : TRect;
begin

{You can initialize ThisRect for what ever value you need.
If all you need to print is the memo then you could specify
the margins of the page. Make sure you specify the coordinates
in Pixels rather then inches}

   DrawText(Printer.Handle, szText, StrLen(szText), ThisRect,
            DT_WORDBREAK or DT_LEFT or DT_CALCRECT);

  {The first call to DrawText will change the value of ThisRect to
        fit the text. The second call to DrawText will actually draw the
text.}

   DrawText(Printer.Handle, szText, StrLen(szText), ThisRect,
            DT_WORDBREAK or DT_LEFT );

Here is the function to change from InchesToPixel. It will be different
for vertical because some printers may print at 300x600 resolution

function InchesToPixelsHorizontal( Inches: Single ): Integer;

   { Convert the horizontal inches represented in 'Inches' to pixels }

   var

      Value: Single;
      Buffer: String;
      I: Integer;
      PixelsPerInchHorizontal : integer;        

   Begin

   PixelsPerInchHorizontal :=
             GetDeviceCaps( Printer.Handle,LOGPIXELSX );

   Value := Inches * PixelsPerInchHorizontal;
   Buffer := FloatToStr( Value );

   { If there is a decimal point in 'Buffer', remove it. }
   I := 1;
   While( (Buffer[I] <> '.') And (I <= Length(Buffer)) ) Do
      Inc( I );
   Buffer[0] := Chr( I-1 );

   Result := StrToInt( Buffer );
   End;

--
                            \\\|///
                          \\  ~ ~  //
                           (  @ @  )
************************-oOOo-(_)-oOOo-**************************************
Imran Hussain                            E-mail: imr...@ix.netcom.com
1 Executive Dr, Suite 130                Phone : (908)321-0340
Somerset, NJ 08820                       Work  : (908)469-4070
*********************************-Oooo.-*************************************
                        .oooO     (   )
                        (   )      ) /
                         \ (      (_/
                          \_)

Re:Printing a TMemoField


In article <3266EB40.5...@io.com>, Haldun Unalmis <unal...@io.com>
writes

Quote
>Tim,

>What if line[lineno] is wider than the line width? It chops of the rest
>of the line.

Fair point, so we're going to have to code our own word-wrap.

You can test the length of the line in the current font using
    TextWidth(line[lineno]).

Converting this to the position within line[lineno] of the last
character that can fit on a line might be tricky.

If I get time today I'll knock up some code to do it.

--
Tim Stannard -  Ad Hoc Computing, Addlestone, Surrey, UK
                Tel/Fax: 01932 830572  Mob: 0589 918184
                e-mail: stann...@adhoc.demon.co.uk

Re:Printing a TMemoField


Why bother.

(1). wordwrap code is there for all to see in printers.pas (if you have the
VCL source).
(2). drawtext() does this for you already:
"The DrawText function draws formatted text into a given rectangle. It
formats text by expanding tabs into appropriate spaces, aligning text to
the left, right, or center of the rectangle, and breaking text into lines
that fit within the rectangle."

--
Paul Motyer
pa...@linuxserver.pccity.com.au
SoftStuff, Croydon, Vic,  Australia, 3136.

Tim Stannard <T...@adhoc.demon.co.uk> wrote in article
<L1qDoHAIAzZyE...@adhoc.demon.co.uk>...

Quote
> In article <3266EB40.5...@io.com>, Haldun Unalmis <unal...@io.com>
> writes
> >Tim,

> >What if line[lineno] is wider than the line width? It chops of the rest
> >of the line.

> Fair point, so we're going to have to code our own word-wrap.

> You can test the length of the line in the current font using
>     TextWidth(line[lineno]).

> Converting this to the position within line[lineno] of the last
> character that can fit on a line might be tricky.

> If I get time today I'll knock up some code to do it.

> --
> Tim Stannard -  Ad Hoc Computing, Addlestone, Surrey, UK
>                 Tel/Fax: 01932 830572  Mob: 0589 918184
>                 e-mail: stann...@adhoc.demon.co.uk

Other Threads