Solved

StringList or Memo Print

Posted on 2000-04-03
7
511 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Component or function to create an ICS-file 2 92
Delphi - replicating a form 8 57
find a node in VST 2 47
Delphi inherited method 6 42
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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

15 Experts available now in Live!

Get 1:1 Help Now