Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

StringList or Memo Print

Posted on 2000-04-03
7
537 Views
Last Modified: 2010-04-04
Could you please help me to print
a textfile loaded in a stringlist or
in a memo ?

Regards,

Pascal
0
Comment
Question by:F31203
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 2679822
Why you don't use Quick Reporst and TQRMemo?

---
Igor.
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2679864
- or TRichEdit
/PL
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2679887
Exactly from Borland
-----------------------
TI785D.txt   Printing the contents of a TMemo or TListbox
    Category   :VCL
    Platform    :All
    Product    :Delphi  All

    Description:
    Q: How can I print all of the lines within a TMemo or TListbox component?

    A: The function below accepts a TStrings object as a parameter and prints
       out each string to the default printer.  Because it uses a TStrings, the
       function will work with any type of component that contains a
       TStrings-type property, such as a TDBMemo or TOutline.

    { Begin code listing }

    uses Printers;

    procedure PrintStrings(Strings: TStrings);
    var
      Prn: TextFile;
      i: word;
    begin
      AssignPrn(Prn);
      try
        Rewrite(Prn);
        try
          for i := 0 to Strings.Count - 1 do
            writeln(Prn, Strings.Strings[i]);
        finally
          CloseFile(Prn);
        end;
      except
        on EInOutError do
          MessageDlg('Error Printing text.', mtError, [mbOk], 0);
      end;
    end;

    { End code listing }

    To print out the contents of a TMemo or TListbox, use the following
    code:

    PrintStrings(Memo1.Lines);

    or

    PrintStrings(Listbox1.Items);


------
Igor.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:F31203
ID: 2680169
In fact, it is a console application.
When I try your code, I receive the following message :

Exception EInvalidOperation.
Control '' has no parent window.

Any idea of what it is ?

Pascal
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2680212
I will check it........
0
 
LVL 9

Accepted Solution

by:
ITugay earned 50 total points
ID: 2680255
This sample working fine:
---------------
program p3;
{$APPTYPE CONSOLE}
uses SysUtils, Printers, Classes, Dialogs;

procedure PrintStrings(Strings: TStrings);
var
  Prn: TextFile;
  i: word;
begin
  AssignPrn(Prn);
  try
    Rewrite(Prn);
    try
      for i := 0 to Strings.Count - 1 do
        writeln(Prn, Strings.Strings[i]);
    finally
      CloseFile(Prn);
    end;
  except
    on EInOutError do
      MessageDlg('Error Printing text.', mtError, [mbOk], 0);
  end;
end;

var L : TStringList;

begin
  L := TStringList.Create;
  L.Add('0');
  L.Add('1');
  L.Add('2');
  L.Add('3');
  PrintStrings(L);
  L.Free;
end.
---------
You may get some problems if you do something like this:

  M:=TMemo.Create(nil);
.....
  PrintStrings(M.Lines);
-------
Try to avoid of creating visual components in console application, especially if it need parent form.
------
Regards,
Igor.



0
 

Author Comment

by:F31203
ID: 2680564
Thanks for your help Igor,

Pascal
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 119
Working with hours 3 65
Dev express lookupcombo 3 35
MS Access from Delphi 31 60
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question