Solved

StringList or Memo Print

Posted on 2000-04-03
7
527 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now