Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

StringList or Memo Print

Posted on 2000-04-03
7
Medium Priority
?
575 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

670 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