Morphios
Morphios

Reputation: 25

Getting Delphi to print a two page document onto one A4 with two coulmns

I need help setting up printing in Delphi XE3 / RAD Studio XE3. I have created a form intended to be used on a dot matrix printer so the normal .print method does not work as it prints the background of the form. All information is being written into the RichEdit box but spans over two pages. I need that information to be printed onto one A4 page with two columns (half of the information on the left and the rest of the information on the right) on one page The problem I am having with tabs is, since most of the information will be entered by the user, I will not know how many tabs to use to get the center of the page and thus have alignment problems.

Upvotes: 0

Views: 867

Answers (1)

Ken White
Ken White

Reputation: 125620

You don't need to send EM_LINEINDEX messages to display text in two columns.

Here's an example of added tab-separated columns to a TRichEdit. It's clearly not using the text you're trying to output, because I wouldn't likely have the registry entries you're trying to access and therefore couldn't test before posting. It should get you started (but see my note below before doing so).

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to 50 do
    RichEdit1.Lines.Add(Format('%d'#9'This is line %d', [i, i]));
end;

The simplest way to print the TRichEdit (if all of the content will fit on a single page) is to simply call TRichEdit.Print.

With that being said, creating a visual control that you'll never display is usually the wrong approach. All versions of Delphi that have ever been released come with some sort of reporting engine (Quick Reports, Rave Reports, Fast Reports) that are designed to easily create printed output. XE3 comes with Fast Reports, which would make very short work of this type of report and would allow you to control output very accurately. If you're going to be working with Delphi, it's worth becoming familiar with its reporting components; they'll save you lots of work, code and frustration in a very short time frame.

Upvotes: 1

Related Questions