Recent

Author Topic: Printing? I have a question  (Read 741 times)

What I can do

  • Full Member
  • ***
  • Posts: 183
Printing? I have a question
« on: July 06, 2024, 10:24:06 pm »
two different senariaos
1). contained with in loop
2). accessed outside loop

1) contained with in loop //no errors

Code: Pascal  [Select][+][-]
  1. var
  2.  pDoc:Integer;
  3.  
  4.  
  5. procedure TForm1.SomeButtonClick(sender:TObject);
  6.  procedure DoMonthReport(aDoc:TPrinter);
  7.  begin
  8.   //print document on aDoc.Canvas
  9.  end;
  10.  Procedure DoYearReport(aDoc:TPrinter);
  11.  begin
  12.   //Print document on zDoc.Canvas
  13.  end;
  14. begin
  15.  pDOC:=1;
  16.  if PrintDialog1.Execute then
  17.   begin
  18.     case pDoc of
  19.      1:DocMonthReport(Printer);
  20.      2:DocYearReport(Printer);
  21.     end;
  22.   end;
  23. end;
  24.  

2). accessed outside loop //errors so big it will not even compile
Code: Pascal  [Select][+][-]
  1. var
  2.  pDoc:Integer;
  3.  
  4.  
  5. Procedure TForm1.DocMonthReport(aDoc:TPrinter);
  6. begin
  7.  //print aDoc.Canvas
  8. end;
  9.  
  10. Procedure TForm1.DocYearReport(aDoc:TPrinter);
  11. begin
  12.  //print zDoc.Canvas
  13. end;
  14.  
  15. Procedure TForm1.Someuttonlick(Sender:TObject);
  16. begin
  17.  var
  18.  pDoc:=1;
  19.  GoPrint;
  20. end;
  21.  
  22. Procedure TForm1.GoPrint;
  23. begin
  24.  if PrintDialog1.execute then
  25.   begin
  26.    case pDoc of
  27.     1:DocMonthReport(Printer);
  28.     2:DocYearReport(Printer);
  29.    end;
  30.   end;
  31. end;

Is there a way to make this work?
« Last Edit: July 07, 2024, 01:12:28 am by What I can do »

silvercoder70

  • Full Member
  • ***
  • Posts: 200
    • Tim Coates
Re: Printing? I have a question
« Reply #1 on: July 06, 2024, 10:56:24 pm »
You need to put

Procedure GoPrint;

above

Procedure Someuttonlick(Sender:TObject);

otherwise declare GoPrint as forward.

Also, might be helpful to pass pDoc as parameter to GoPrint. I suspect you are getting an error about an undefined variable?

- Tim
🔥 Pascal Isn’t Dead -> See What It Can Do: @silvercoder70 on YouTube

What I can do

  • Full Member
  • ***
  • Posts: 183
Re: Printing? I have a question
« Reply #2 on: July 07, 2024, 01:14:57 am »
YES! YES!
Your right and i have fixed that. The happens before compile is complete and I'm not sure what the exact message was.
Exit Code 1 errors 1
identifier not found TPrinter
« Last Edit: July 07, 2024, 03:32:04 am by What I can do »

 

TinyPortal © 2005-2018