Jump to content

Free Pascal - Output to Printer Problem

- - - - -

  • Please log in to reply
6 replies to this topic

#1
TheKingfish

TheKingfish

    Newbie

  • Members
  • PipPip
  • 12 posts
I am new to Free Pascal; a longtime Turbo user having trouble getting the program to output (write) to the printer. The FP printer set-up has LPT1 in place, and readily prints a copy of the program to the printer. Win 98 is in use here. However, when I run the following code:

Writeln (lst, ‘Print to printer’);

I get a 103 runtime error. I have a “Uses Printer;” statement in place within the code. This arrangement was the working convention for Turbo, but it doesn’t work for FP. It seems that I’m missing something. What is the remedy here? Thanks.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Do you have a printer that uses LPT1, or a USB printer?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
TheKingfish

TheKingfish

    Newbie

  • Members
  • PipPip
  • 12 posts
Yes, my old dot-matrix printer is hooked to the LPT1 port; it will print the full program via the pull-down menu, so it's functioning and sees the FP. Per my inquiry, I cannot print utilizing a command within the FP code.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What version of FP are you using?

Can you provide enough code for us to do testing for errors?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
TheKingfish

TheKingfish

    Newbie

  • Members
  • PipPip
  • 12 posts
My FP version is 2.4.4. The full-program code is as follows:

[FONT="]PROGRAM sample (input, output, infile, outfile);[/FONT]
[FONT="]Uses Printer;[/FONT]
[FONT="][/FONT]

[FONT="]VAR[/FONT]
[FONT="] j,k: integer;[/FONT]
[FONT="] infile, outfile: text;[/FONT]
[FONT="] [/FONT]
[FONT="]BEGIN {main program}[/FONT]
[FONT="] writeln ('Enter two numbers to be multiplied');[/FONT]
[FONT="] readln (j,k);[/FONT]
[FONT="] writeln (lst, j, ' multiplied by ', k ,' equals ', j*k)[/FONT]
[FONT="]END. {main program}[/FONT]

This outputs to the printer in Turbo but not FP. Thanks for your help,

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
After doing some searching, I have a feeling you are doing things wrong for FreePascal.

Print an image when printer in raw mode.

Also, based on this site, you really need to get a different version: Windows 95 is not supported by Free Pascal 2.4.4 compiler
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
TheKingfish

TheKingfish

    Newbie

  • Members
  • PipPip
  • 12 posts
[FONT="]A solution to my problem! While I am new to Free Pascal, it seems that FP does not directly support programs that output directly to a printer. Conversely, Turbo provided a convenient “LST” command that readily threw output to a printer. However, there is a way in FP to print directly from the program.[/FONT]
[FONT="] [/FONT]
[FONT="]The basic idea is to define a text file variable, and assign it a name that refers to a printer port. Then you open the file variable (using rewrite) and use the file variable to send output to the printer (using write or writeln). To print to a printer attached to the first printer port (i.e. parallel port) on your computer, use “LPT1” as the name assigned to the file variable (make sure “LPT1” is present in your printer set-up). While there is some written direction in the FP manual, a good code-example is missing. Below is code that will work for the purpose of utilizing the Turbo format. I hope this technique is helpful to anyone who is transitioning to FP with old printers and old paradigms.[/FONT][FONT="][/FONT]
[FONT="] [/FONT]
[FONT="]PROGRAM sample;[/FONT]
[FONT="]Uses Printer;[/FONT]
[FONT="] [/FONT]
[FONT="]VAR[/FONT]
[FONT="] lst: text;[/FONT]
[FONT="] [/FONT]
[FONT="]BEGIN {main program}[/FONT]
[FONT="] assign (lst, 'lpt1');[/FONT]
[FONT="] rewrite (lst);[/FONT]
[FONT="] writeln (lst, 'Test print to printer');[/FONT]
[FONT="] close (lst)[/FONT]
[FONT="]END. {main program}[/FONT]




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users