Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Free Pascal - Output to Printer Problem

runtime

  • Please log in to reply
6 replies to this topic

#1 TheKingfish

TheKingfish

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 13 January 2012 - 05:40 AM

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.
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 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

Posted 13 January 2012 - 01:32 PM

Do you have a printer that uses LPT1, or a USB printer?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 TheKingfish

TheKingfish

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 13 January 2012 - 04:43 PM

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.
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 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

Posted 13 January 2012 - 08:50 PM

What version of FP are you using?

Can you provide enough code for us to do testing for errors?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 TheKingfish

TheKingfish

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 16 January 2012 - 07:23 PM

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,
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 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

Posted 16 January 2012 - 08:06 PM

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
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 TheKingfish

TheKingfish

    CC Newcomer

  • Member
  • PipPip
  • 12 posts

Posted 21 January 2012 - 08:24 PM

[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]
  • 0





Also tagged with one or more of these keywords: runtime

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download