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?
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?