Recent

Author Topic: Printing memo lines weird issue  (Read 2340 times)

GregO51

  • New Member
  • *
  • Posts: 13
Printing memo lines weird issue
« on: June 17, 2019, 06:13:11 am »
I have a memo field on an invoicing form. The invoice form I have will allow up to to 3 lines of text for a particular debit. If I have just the first line on the form partially filled and the next two lines empty I get a repeat of the first line on the second line prefixed with various characters even though there is nothing on the second line This is what prints:

Carpet and upholstery cleaning in all common areas
3arpet and upholstery cleaning in all common areas 

This is what's showing on the invoice:
Carpet and upholstery cleaning in all common areas
Any ideas? I am printing each line from the memo assuming that the blank lines will not print

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: Printing memo lines weird issue
« Reply #1 on: June 17, 2019, 07:53:00 am »
Looks like you are over-indexing? range is 0..2 not 3.
Can you add a small example?
Specialize a type, not a var.

GregO51

  • New Member
  • *
  • Posts: 13
Re: Printing memo lines weird issue
« Reply #2 on: June 17, 2019, 08:12:41 pm »
This is the code to print the lines of the memo field on an invoice form:
  textout(round(prntx*150),round(prnty*1440),MccInvoiceform.Invtabdebdate2.value);

  textout(round(prntx*425),round(prnty*1440),MccInvoiceForm.dbmemo2.lines[0]);
  textout(round(prntx*425),round(prnty*1510),MccInvoiceForm.dbmemo2.lines[1]);
 
Problem is it is printing a near copy of MemoLine0 on memoline1 event though there is nothing in memoline1.

Whats on the invoice memo:
Carpet and upholstery cleaning in all common areas

whats on the PRINTED Invoice:
Carpet and upholstery cleaning in all common areas
3arpet and upholstery cleaning in all common areas     /////Extra and unwanted text

I don't get it............

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Printing memo lines weird issue
« Reply #3 on: June 17, 2019, 11:22:37 pm »
Move the Line to a local string and then print that String...

It's possible a CRLF line is being returned. I am seeing that as well here dealing with List Boxes
and such, a CRLF is being attached.
The only true wisdom is knowing you know nothing

GregO51

  • New Member
  • *
  • Posts: 13
Re: Printing memo lines weird issue
« Reply #4 on: June 18, 2019, 02:01:22 am »
I've tried that but to no avail....... If I have a description that wordwraps to the 2nd line in the memo field it prints fine. If it doesn't wordwrap to the next line and I move DbMemoLine[1] (the 2nd memo line) to another string there is a portion of DBMemoLine[0] that is also moved to the other string even thought there is nothing showing in the 2nd memo field line!  I have tried to conditionally print memo line 2 but nothing seems to work properly....


jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Printing memo lines weird issue
« Reply #5 on: June 18, 2019, 10:57:30 pm »
I see..

Create a Local TStringList, assign the list from the Tmemo and print from there.

A Memo can do strange things like that because it's returning the contents of the screen.

MySL := TStringList.Create;

MySL.Text := Memo.Text;

now print from MySL.

Btw, maybe you could use the TsynEdit instead, that is much better in many cases.

« Last Edit: June 18, 2019, 11:05:15 pm by jamie »
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Printing memo lines weird issue
« Reply #6 on: June 19, 2019, 01:14:50 am »
A Memo can do strange things like that because it's returning the contents of the screen.

That's not true. Reading/writing TMemo.Lines accesses the underlying TStrings descendant it uses. It has nothing to do with how those strings are in turn "drawn" on the screen. Unless there are a WS differences I'm unaware of?

Quote from: jamie
Create a Local TStringList, assign the list from the Tmemo and print from there.
Code: Pascal  [Select][+][-]
  1. MySL := TStringList.Create;
  2. MySL.Text := Memo.Text;
now print from MySL.

That's wasteful of memory. Iterating through Memo.Lines[] and printing each should suffice. One just have to care about some pitfalls, like trying to print empty lines or ones that are too long (you have to word-wrap the line yourself) or contain control chars, etc. but all in all it is relatively easy.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Printing memo lines weird issue
« Reply #7 on: June 19, 2019, 01:25:51 am »
Try a Tmemo in Windows some time and force the first line to word wrap around..

Then Play with the indexes from the memo.

I've found that LINE 1 is not aways line 1 but the tail end of LINE 0 due to the wrap around.

 This may behave differently in other widget sets but in Windows the last time I saw this  it was
a problem...
 
 not all the controls in these widgets work the same across the board.
The only true wisdom is knowing you know nothing

GregO51

  • New Member
  • *
  • Posts: 13
Re: Printing memo lines weird issue
« Reply #8 on: June 19, 2019, 05:57:58 am »
   Well I discovered a way to solve the problem. Previously I when I tried moving the blank memo line to a tedit or caption on a control random characters and text from the non blank line would show up. It's strange as on the screen the memo line (2nd line) was empty of any characters. I  tried conditionally printing the second (blank memo line) only if it had text. For some reason that supposedly blank line would print the random characters and parts of the first line no matter what conditions I put on it.
   I found that using DBMemo1.Lines.Count the blank line would truly be recognized as being blank.
This is what worked to keep the second line from printing if it indeed was blank:

             if MccInvoiceForm.dbmemo1.Lines.Count>1   then
               textout(round(prntx*425),round(prnty*1320),MccInvoiceForm.dbmemo1.lines[1]);

It's still strange to me why copying or printing a blank memo line that has no text produces a text output............  Thanks for all the suggestions........... Greg
 
               

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Printing memo lines weird issue
« Reply #9 on: June 19, 2019, 07:05:58 am »
The Memo controls are quite simple-minded and, generally, refuse to show anything other than printable characters. That doesn't mean that the characters are not there in the underlying text, just that the memo won't show them so a line aparently blank may well contain something you're not being made aware of.

This is almost certainly what's happening to you: something is being read (from a database?) that aren't printable characters and while the memo simply don't show it TextOut() tries, nonetheless, to print it out to the printer.

ETA:

jamie, you're right. I made some tests in Windows (XP and 7) and it seems the only way to get the strings as they really are is by reading Text. Duly noted, sir! :)

(In Linux/GTK--and other *nixen, I suppose) it works as it should: reading Lines[] or Lines.Strings[] gets the full, unwrapped line).
« Last Edit: June 19, 2019, 09:11:43 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: Printing memo lines weird issue
« Reply #10 on: June 19, 2019, 09:40:30 am »
Try something like this (not my code):
Code: Pascal  [Select][+][-]
  1. {$I+}uses Printer;
  2. // pass memo.lines to this
  3. procedure PrintStrings(Strings: TStrings);
  4. var
  5.   Prn: TextFile;
  6.   i: word;
  7. begin
  8.   AssignPrn(Prn);
  9.   try
  10.     Rewrite(Prn);
  11.     try
  12.       for i := 0 to Strings.Count - 1 do
  13.         writeln(Prn, Strings.Strings[i]);  // or simply strings[i]
  14.     finally
  15.       CloseFile(Prn);
  16.     end;
  17.   except
  18.     on EInOutError do
  19.       MessageDlg('Error Printing text.', mtError, [mbOk], 0);
  20.   end;
  21. end;

[edit]
See also example from the manual: https://www.freepascal.org/docs-html/rtl/printer/assignlst.html that uses unit printer, not printers....
« Last Edit: June 19, 2019, 10:27:19 am by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018