Solved

printing from delphi

Posted on 2004-04-08
6
413 Views
Last Modified: 2010-04-05
hi how to print info from the access database or from the grid in delphi


to either a network printer or local printer
0
Comment
Question by:zgeorge_2
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789049
You will need a Report component

You can use either Rave Reports or quick reports or a ton of other ones

WHat version of Delphi Do you use?

Do you have Rave Components ?

Shane
0
 

Author Comment

by:zgeorge_2
ID: 10789055
have delphi7

well i have Rave Raports Component (george(at) unip(os.com)

(forgot about the tables




thank you


0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789072
yes forget about the tables. If you want to draw me up a NICE (well thought out)  specification on how that works, then i will work on it for you, until then -  im gonna stay away

Shane
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:zgeorge_2
ID: 10789078
ok can we print
 

the grid

0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789091
Yes,
Go back to yahoo

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10789172
Um, for what you need, a simple solution of sending the info from your Receipt in your POS app to a modal form with a Memo will be suffice.

Then utilizing this procedure below to print.

procedure TfrmMainPOS.PrintMemo( aMemo: TMemo;
                     centerVertical, centerHorizontal: Boolean );
  Var
    topMargin, bottomMargin, leftMargin, rightMargin: Integer;
    x,y: Integer;
    maxLineLength: Integer;
    linecounter: Integer;
    lineheight : Integer;
  Begin
    { Set the default margins to 1 inch for top, bottom, 0.75 inch
      for left and right margins. GetDeviceCaps is used to get the
      printers resolution (dots per inch). The margin variables
      contain the position of the margin on paper, in dots, not the
      distance from the border of the printing region! }
    topMargin := GetDeviceCaps( Printer.Handle, LOGPIXELSY );
    bottomMargin := Printer.PageHeight - topMargin;

    leftMargin := GetDeviceCaps( Printer.handle, LOGPIXELSX ) * 3 div 4;
    rightMargin := Printer.PageWidth - leftMargin;

    { Start the print job, assign the memo font to the printer canvas.
      Note that we have to make sure the print job is closed properly,
      thus the try finally block. }
    Printer.BeginDoc;
    try
      Printer.Canvas.Font.PixelsPerInch :=
        GetDeviceCaps( Printer.Canvas.Handle, LOGPIXELSY );
        { This is really only necessary for Delphi 1, due to a
          buglet. }
      Printer.Canvas.Font:= aMemo.Font;

      { Determine the height of a line in pixels }
      lineHeight := Printer.Canvas.TextHeight('Ay');

      If centerHorizontal Then Begin
        { Iterate once over all lines of the memo and determine the
          length, in pixels, of the longest line. We need that to
          adjust the leftMargin to center the text. }
        maxLineLength := 0;
        For linecounter := 0  To aMemo.Lines.Count-1 Do Begin
          x:= Printer.Canvas.TextWidth( aMemo.Lines[linecounter]);
          If x > maxLineLength Then
            maxLineLength := x;
        End; { For }

        { Adjust the leftMargin to center the text into the
          available space between the current margins. }
        x := leftMargin +
             (rightMargin-leftMargin-maxLineLength) div 2;
        If x < leftMargin Then Begin
          { Problem, longest line does not fit into the available
            space! We leave the margin untouched, the line will
            be truncated. }
        End { If }
        Else
          leftMargin := x;
      End; { If }

      If centerVertical Then Begin
        { Calculate the vertical space needed to print all lines,
          adjust the topMargin to center the text as needed. }
        y := lineHeight * aMemo.Lines.Count;
        If y < (bottomMargin - topMargin) Then Begin
          topMargin :=
            topMargin + (bottomMargin - topMargin - y) div 2;
        End; { If }
        { Else
            space needed is larger than the height of a page,
            so ignore the center request. }
      End; { If }

      { Margins have been calculated, so we are finally set up
        to start printing lines. In the following code x and y
        hold the starting position of the next line. }
      x:= leftMargin;
      y:= topMargin;
      For linecounter := 0  To aMemo.Lines.Count-1 Do Begin
        Printer.Canvas.TextOut( x, y, aMemo.Lines[linecounter]);
        y := y + lineHeight;
        If y >= bottomMargin Then Begin
          { Eject the page and start a new one, but only if
            the line we have just printed is not the last line
            anyway. EndDoc will eject the current page. }
          If linecounter < (aMemo.Lines.Count-1) Then Begin
            Printer.NewPage;
            y:= topMargin;
          End;
        End; { If }
      End; { For }
    finally
      Printer.EndDoc;
    end;
  End; { PrintMemo }

Shane
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi parse string to params 3 121
LAN or WAN ? 11 90
Base1 Encode/Decode 3 77
enhance the following code 3 29
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

17 Experts available now in Live!

Get 1:1 Help Now