# Native Code > برنامه نویسی در Delphi > مباحث عمومی دلفی و پاسکال >  خالی کردن اطلاعات موجود در حافظه پرینتر

## Delphi&Kylix_2939

با سلام
کسی می تونه کدی بنویسه که اطلاعات موجود در حافظه پرینتر رو تخلیه کنه 
ممنون می شم

----------


## merced

اينجا رو بخون 
http://www.delphi3000.com/articles/article_1699.asp?SK=
اولين پستش ليست job  ها رو برگردونده 
و پست Spool job pause, delete هم چيزي كه لازم داري رو گفته 



uses WinSpool; 
………………….. 
type JOB_INFO_1_ARRAY = Array of JOB_INFO_1; 
………………….. 
Function GetSpoolerJobs(sPrinterName : String) : JOB_INFO_1_ARRAY; 
var 
         i : Integer; 
         hPrinter   : THandle; 
         bResult    : Boolean; 
         cbBuf      : DWORD; 
         pcbNeeded  : DWORD; 
         pcReturned : DWORD; 
         aJobs      : Array[0..99] of JOB_INFO_1; 
begin 
         cbBuf := 1000; 

         bResult := OpenPrinter(PChar(sPrinterName), hPrinter, Nil); 
         if NOT bResult then begin 
            ShowMessage('Error opening the printer'); 
            exit; 
         end; 

         bResult := EnumJobs(hPrinter,0,Length(aJobs),1,@aJobs,cbBuf,p  cbNeeded,pcReturned); 
         if NOT bResult then begin 
            ShowMessage('Error Getting Jobs information'); 
            exit; 
         end; 
          
         ClosePrinter(hPrinter);  

         for i:=0 to pcReturned-1 do begin 
             if aJobs[i].pDocument <> Nil then begin 
                SetLength(Result, Length(Result)+1); 
                Result[Length(Result)-1] := aJobs[i]; 
             end; 
         end; 
end; 

An example of use: 
1- Create a new project with a StringGrid and a Timer. 
2- Set “ColCount” and “RowCount” properties of the string grid to 20. 
3- Set the “Interval” property of the Timer to 500. 
4- On the “OnTime” event of the timer write the following code : 

procedure TForm1.Timer1Timer(Sender: TObject); 
var 
          i, ii : Integer; 
          aJobs : JOB_INFO_1_ARRAY; 
begin 
          for i:=0 to StringGrid1.ColCount-1 do 
              for ii:=0 to StringGrid1.RowCount-1 do StringGrid1.Cells[i,ii] := ''; 

          aJobs := GetSpoolerJobs('HP LaserJet 6L PCL'); 

          for i:=0 to Length(aJobs)-1 do begin 
              StringGrid1.Cells[i,0] := aJobs[i].pPrinterName; 
              StringGrid1.Cells[i,1] := aJobs[i].pMachineName; 
              StringGrid1.Cells[i,2] := aJobs[i].pUserName; 
              StringGrid1.Cells[i,3] := aJobs[i].pDocument; 
              StringGrid1.Cells[i,4] := aJobs[i].pDatatype; 
              StringGrid1.Cells[i,5] := aJobs[i].pStatus; 
              StringGrid1.Cells[i,6] := IntToStr(aJobs[i].Status); 

              case aJobs[i].Status of 
                   JOB_STATUS_PAUSED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAUSED'; 
                   JOB_STATUS_ERROR: StringGrid1.Cells[i,6] := 'JOB_STATUS_ERROR'; 
                   JOB_STATUS_DELETING: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETING'; 
                   JOB_STATUS_SPOOLING: StringGrid1.Cells[i,6] := 'JOB_STATUS_SPOOLING'; 
                   JOB_STATUS_PRINTING: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTING'; 
                   JOB_STATUS_OFFLINE: StringGrid1.Cells[i,6] := 'JOB_STATUS_OFFLINE'; 
                   JOB_STATUS_PAPEROUT: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAPEROUT'; 
                   JOB_STATUS_PRINTED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTED'; 
                   JOB_STATUS_DELETED: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETED'; 
                   JOB_STATUS_BLOCKED_DEVQ: StringGrid1.Cells[i,6] := 'JOB_STATUS_BLOCKED_DEVQ'; 
                   JOB_STATUS_USER_INTERVENTION: StringGrid1.Cells[i,6] := 'JOB_STATUS_USER_INTERVENTION'; 
                   JOB_STATUS_RESTART: StringGrid1.Cells[i,6] := 'JOB_STATUS_RESTART'; 
                   JOB_POSITION_UNSPECIFIED: StringGrid1.Cells[i,6] := 'JOB_POSITION_UNSPECIFIED'; 

              else StringGrid1.Cells[i,6] := 'Unknown status...'; 
              end; 
          end; 

          StringGrid1.Refresh; 
end; 




============================
var 
          bResult        : Boolean; 
          hPrinterHandle : THandle; 
          sPrinterName   : PChar; 
          aJobs          : JOB_INFO_1_ARRAY; 
begin 
          sPrinterName := 'HP LaserJet 6L PCL'; 
           
          //Retrieve all jobs using the “GetSpoolerJobs” that is declared in this article 
          aJobs := GetSpoolerJobs(sPrinterName); 

          if Length(aJobs) = 0 then begin 
             ShowMessage('There is no jobs in the spooler'); 
             exit; 
          end; 

          //get the printer handle 
          bResult := OpenPrinter(sPrinterName, hPrinterHandle, Nil); 
          if NOT bResult then begin 
             ShowMessage('Error Getting the printer handle'); 
             exit; 
          end; 

          //to DELETE the first job in the spooler 
          SetJob(hPrinterHandle,aJobs[0].JobId,1,@aJobs[0], JOB_CONTROL_CANCEL); 

          //to PAUSE the first job in the spooler 
          SetJob(hPrinterHandle,aJobs[0].JobId,1,@aJobs[0], JOB_CONTROL_PAUSE); 

          //to RESUME the first job in the spooler after pausing it 
          SetJob(hPrinterHandle,aJobs[0].JobId,1,@aJobs[0], JOB_CONTROL_RESUME); 

end;

----------

