Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing problems again

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
Ok, I now have the following code to print out stuff properly:

procedure TfrmCreate.mnuPrintClick(Sender: TObject);
var
i,k:integer;
cardType:String;
Temp:Single;
PrintText:TextFile;
Types:Array[1..5] of Integer;
begin
ToSend.Lines.Clear;
AssignPrn(PrintText); {assigns PrintText to the printer}
Rewrite(PrintText); {creates and opens the output file}
Printer.Title := 'Current Deck';
Printer.BeginDoc;

For i := 1 to 5 do Types := 0;
For k := 1 to 5 do
begin
If GSDef.StatSets[k].Name <> '' then
begin
Printer.Canvas.Font := FontHeaders.Font;
ToSend.Lines.Add(GSDef.StatSets[k].Name);
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;

Printer.Canvas.Font := FontText.Font;
For i := 0 to (lstDeck.Items.Count-1) do
begin
cardType := GCCS(StrToInt(lstDeckUID.Items));
If GSDef.StatSets[k].Name = cardType then
begin
inc(Types[k]);
ToSend.Lines.Add(lstDeck.Items);
end;
end;
ToSend.Lines.Add(' ');
ToSend.Lines.Add(' ');
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;
end;
end;

ToSend.Lines.Add(' ');
ToSend.Lines.Add(' ');
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;

Printer.Canvas.Font := FontHeaders.Font;
ToSend.Lines.Add('Summary');
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;

Printer.Canvas.Font := FontText.Font;
For i := 1 to 5 do
begin
Temp := (Round(((Types/lstDeck.Items.Count)*100)*10)/10);
If Types > 0 then ToSend.Lines.Add(concat(GSDef.StatSets.Name,': ',IntToStr(Types),' (',FloatToStr(Temp),'%)'));
end;
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;
Printer.EndDoc;
CloseFile(PrintText); {Closes the printer variable}
end;

ToSend is a memo box where I store the stuff to be printed, FontHeaders and FontText are labels that I use to set the fonts that I want.

It gives me an error saying 'Printing in progress' when I try to run it, and the print queue shows the job as spooling forever until I close the program and then the print driver gives me the 'Failed to print' error message. When it gives me the 'Printing in progress' error, Delphi shows me the code that caused the error as being the final

end;

line in the bit that has the

Application.Initialize;
Application.Title := 'DeckBuild';
Application.CreateForm(TfrmSplash, frmSplash);
Application.CreateForm(TfrmMenu, frmMenu);

and so on lines.

I know that the variables all have the right values in because the program would have died ages before that if they didn't (plus I've checked them all at some point during development). I'm assuming my code for sending stuff to the printer is completely off, can anyone help me?
 
You migbht not be able to make it out because I left the TGML processing on (doh!), but I've moved the BeginDoc, so it's now

Printer.BeginDoc;
Repeat
Until (Printer.Printing = False);
Printer.EndDoc;

At the end (where it's just EndDoc above). Still get the same problem.
 
Without TGML, and cut down a bit:

ToSend.Lines.Clear;
AssignPrn(PrintText); {assigns PrintText to the printer}
Rewrite(PrintText); {creates and opens the output file}
Printer.Title := 'Current Deck';

Printer.Canvas.Font := FontHeader.Font;
ToSend.Lines.Add('Summary');
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;

Printer.Canvas.Font := FontText.Font;
For i := 1 to 5 do
begin
Temp := (Round(((Types/lstDeck.Items.Count)*100)*10)/10);
If Types > 0 then ToSend.Lines.Add(concat(GSDef.StatSets.Name,': ',IntToStr(Types),' (',FloatToStr(Temp),'%)'));
end;
Writeln(PrintText, ToSend.Lines.Text);
ToSend.Lines.Clear;
Printer.BeginDoc;
Repeat
Until (Printer.Printing = False);
Printer.EndDoc;
CloseFile(PrintText); {Closes the printer variable}
 
Have you tried running the debugger on your program to find out which statement is causing the 'Printing in Progress' message ?

Andrew
 
hi

for me you make a general mistake accessing the printer.
Either you work with AssignPRT OR you use Printer.BeginDOC, but not both at the same time.

Normally I print the following way:
Printer.BeginDOC;
Printer.Canvas.Font.Assign(myFont);
for i := 0 to blabla do
Printer.Canvas.TextOut(myX, myY, myText);
Printer.EndDOC;

to achieve a nice printer font you have to set myFont.Size instead of myFont.Height.

regards
Rod
 
But if I use your example, how do I keep track of where I need to output the next line on the canvas?
 
Ok, I've resorted back to what used to work, and it doesn't anymore. I know it's going to be an obvious mistake, but I can't see what. Cut down version:

AssignPrn(PrintText); {assigns PrintText to the printer}
Rewrite(PrintText); {creates and opens the output file}

For k := 1 to 5 do
begin
If GSDef.StatSets[k].Name <> '' then
begin
Writeln(PrintText, concat(GSDef.StatSets[k].Name,':'));

Writeln(PrintText, ' ');
end;
end;

CloseFile(PrintText); {Closes the printer variable}

Can anyone see the problem? I was using something that I'm sure was identical to this originally, but obviously I've changed something by accident.
 
When you say it doesn't work, what do you mean?

Does it compile okay?

If it compiles and runs what happens?

Are there any error messages?

When you use the debugger and single step through your code which statement is failing?

Andrew
 
Sorry, forgot the details.

It sends it and the program doesn't die or give any error messages. The print driver says:

&quot;This document failed to print.&quot;

Followed by the date and time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top