Board index » delphi » TMemo Word Wrap vs. Width Problem

TMemo Word Wrap vs. Width Problem

I'm using D3 build 5.83

I'm attempting to use an invisible TMemo as a way to obtain word-wrap
before writing out text to the printer or print preview screen.

I'm having a problem when repeatedly modifying the width of the TMemo as
when doing tables with varying length columns.  Here's the relavent code:

Creating the instance:

procedure TReportWorks.Loaded;
begin
  inherited Loaded;
  {Create invisible memo here. This will allow
   for faster printing during PrintParagraph
   and table print methods.}
  AMemo := TMemo.Create(Self);
  AMemo.Parent  := Parent;
  AMemo.Visible := false;
  AMemo.Top     := -30;
  AMemo.Height  := 25;
  AMemo.Width   := Screen.PixelsPerInch * 8;
end;

Code causing the problem:

procedure TReportWorks.PrintTableText(AColumn:integer;AText:pchar);
var x,z:integer;
    y:single;
    t:TableRecord;
    DummyCount:integer;
begin
        .
        .
        .

  try
  AMemo.Clear;
  AMemo.Font.Assign(ReportFont);
  AMemo.Width := trunc(0.95*Screen.PixelsPerInch*(t^.Width -
FTableTextHorzOff) / y );

  >> I have checked the contents of AMemo.Width here, both in debug mode
and with a ShowMessage - it's value reads correctly <<

  AMemo.SetTextBuf(AText);

  >> However, when I load the text into the memo, it wordwraps as if the
width of the memo had not been changed.  I verify this by checking the
values of AMemo.Lines.Count below which matches the incorrect results
  printed out or displayed in the print preview.<<

  if AMemo.Lines.Count = 0 then
        DummyCount := 0
  else
        DummyCount := AMemo.Lines.Count - 1;

   .
   .
   .
end;

What's really odd, is the behavior appears to change depending on the
SIZE of ReportFont.  For sizes in the 8-10 point range, AMemo seems to
behave correctly.  However when I use larger sizes, the EFFECTIVE width
of AMemo appears to become "stuck" on the first value it receives, even
though it READS correctly...

I've verified this by varying the first value fed to AMemo.Width and
observing that the word-wrap tracks this value.

Any help on fixing/working around this issue would be greatly
appreciated!!

Best Regards,

dick Bryant
Open Window Software

 

Re:TMemo Word Wrap vs. Width Problem


In article <MPG.11c1c175591b5a28989...@forums.borland.com>,{*word*106} Bryant
wrote:

Quote
> AMemo.Height  := 25;

That value is too small. A memo starts to not show the text if the
height of its format rect (which is a bit smaller than the client
area) is smaller than the text height. You are probably running into
this situation.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:TMemo Word Wrap vs. Width Problem


In article <VA.00003009.017893cb@noname>, 100113.1...@compuXXserve.com
says...
Quote
> In article <MPG.11c1c175591b5a28989...@forums.borland.com>,{*word*106} Bryant
> wrote:
> > AMemo.Height  := 25;

> That value is too small. A memo starts to not show the text if the
> height of its format rect (which is a bit smaller than the client
> area) is smaller than the text height. You are probably running into
> this situation.

> Peter Below (TeamB)  100113.1...@compuserve.com)
> No e-mail responses, please, unless explicitly requested!

Thanks, Pete.  That seems to have handled it.
--
{*word*106} Bryant
Open Window Software
http://www.openwindow.com

Other Threads