Solved

StringList or Memo Print

Posted on 2000-04-03
7
520 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Activex loadlibrary and show parented form issue 6 286
indy Tmemory stream non latin charcter issue 2 98
Delphi and Access based Enumeration 9 47
DBGrid or StringGrid ? 6 70
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 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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

13 Experts available now in Live!

Get 1:1 Help Now