Fast POS Print

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
ardahan
Üye
Mesajlar: 144
Kayıt: 26 Oca 2004 05:17
Konum: İstanbul - Kocaeli - Ardahan
İletişim:

Fast POS Print

Mesaj gönderen ardahan »

Kod: Tümünü seç

procedure TFrmPrint.BtnPrintClick(Sender: TObject);
  function GetCurrentPrinterHandle: THandle;
  var
    Device, Driver, Port : array[0..255] of char;
    hDeviceMode: THandle;
  begin
    Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
    if not OpenPrinter(@Device, Result, nil) then
      RaiseLastWin32Error;
  end;

  Procedure PrintFileToGeneric(Const sFileName: string; ejectPage: boolean );
  Const
    BufSize = 16384;
  Var
    Count : Integer;
    BytesWritten: DWORD;
    hPrinter: THandle;
    DocInfo: TDocInfo1;
    f: file;
    Buffer: array [1..Bufsize] of char;
    ch: Char;
  Begin
//    If not WinSpool.OpenPrinter(GenericPrinter, hPrinter, nil) Then   raise exception.create('Printer not found');
    hPrinter:=GetCurrentPrinterHandle;
    Try
      DocInfo.pDocName := 'MyDocument';
      DocInfo.pOutputFile := Nil;
      DocInfo.pDatatype := 'RAW';
      If StartDocPrinter(hPrinter, 1, @DocInfo) = 0 Then
        Abort;

      Try
        If not StartPagePrinter(hPrinter) Then
          Abort;

        System.Assign(f, sFileName);
        Try
          Reset(f, 1);
          Try
            While not eof(f) Do Begin
              Blockread(f, Buffer, BufSize, Count);
              If Count > 0 Then Begin
                If not WritePrinter(hPrinter, @Buffer, Count, BytesWritten) Then
                  Abort;
              End;
            End;
          Finally
            If ejectPage Then Begin
              ch:= #12;
              WritePrinter( hPrinter, @ch, 1, BytesWritten );
            End;
          End;
        Finally
          EndPagePrinter(hPrinter);
          System.Closefile( f );
        End;
      Finally
        EndDocPrinter(hPrinter);
      End;
    Finally
      WinSpool.ClosePrinter(hPrinter);
    End;
  End;
begin
  printfiletogeneric( 'C:\test.txt', True );
end;
Mehmet Avşar - Analist
Gözyaşlarım sevgimi anlatmıyor mu !
ardahan
Üye
Mesajlar: 144
Kayıt: 26 Oca 2004 05:17
Konum: İstanbul - Kocaeli - Ardahan
İletişim:

Pos Printer Yazdırma rutini - 2

Mesaj gönderen ardahan »

Kod: Tümünü seç

uses WinSpool,Printers; 

..... 

type 
  TPassThroughData = record 
      nLen: Word; 
      Data: array[0..255] of Byte; 
  end; 
.... 


procedure TFrmPrint.BtnTablePrintClick(Sender: TObject); 
  procedure PrintText(s: string); 
  var 
      PTBlock: TPassThroughData; 
  begin 
      PTBlock.nLen := Length(s); 
      StrPCopy(@PTBlock.Data, s); 
      Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil); 
  end; 
begin 
    Printer.BeginDoc; 
    PrintText('CustNo  : '+FloatToStr(Table1CustNo.AsFloat)+#10#13); 
    PrintText('Company : '+Table1Company.AsString+#10#13); 
    PrintText('City    : '+Table1City.AsString+#10#13); 
    Printer.EndDoc; 
end; 
Açıklama :

#10#13 : Bir sonraki satıra geçilmesini sağlar.
PrintText(string) : Yazdırmak istediğiniz ifadeyi yollayacağınız fonksiyon
Gözyaşlarım sevgimi anlatmıyor mu !
Cevapla