Einzelnen Beitrag anzeigen

Natcree

Registriert seit: 5. Mär 2013
502 Beiträge
 
Delphi 7 Enterprise
 
#71

AW: Kassenlade öffnen

  Alt 26. Jun 2014, 11:04
Also habe mal wie am anfang des Threads

Die Function so eingebunden

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, printers, winspool;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure opendrawer();
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
  ESC = #27;
  GS = #29;

  { Commands }

  ESC_em = ESC + #33; { Select print mode }
  ESC_p = ESC+#112; { Generate pulse }
  GS_V = GS + #86; { Select cut mode and cut paper }

  { Parameter }

  Lade1 = #48;
  Lade2 = #49;

  PulsDauer100ms = #050; {* 2ms}
  PulsDauer200ms = #100; {* 2ms}
  PulsDauer300ms = #150; {* 2ms}
  PulsDauer400ms = #200; {* 2ms}
  PulsDauer500ms = #250; {* 2ms}
var
  Form1: TForm1;

implementation

{$R *.dfm}

function RawDataToPrinter(szPrinterName:PChar; lpData:PByte; dwCount:Word) : Boolean;
Var
   hPrinter : THandle;
   DocInfo : DOC_INFO_1;
   dwJob : Word;
   dwBytesWritten : Cardinal;
Begin
   Result:=False;
   if NOT OpenPrinter( szPrinterName, hPrinter, NIL ) then
     Exit;

   DocInfo.pDocName := 'RAWJOB';
   DocInfo.pOutputFile := NIL;
   DocInfo.pDatatype := 'RAW';

   dwJob := StartDocPrinter( hPrinter, 1, @DocInfo );
   if (dwJob = 0 ) Then begin
     ClosePrinter( hPrinter );
     Exit;
   end;


   if not StartPagePrinter( hPrinter ) then begin
     EndDocPrinter( hPrinter );
     ClosePrinter( hPrinter );
     Exit;
   end;


   if not WritePrinter( hPrinter, lpData, dwCount, dwBytesWritten ) then begin
     EndPagePrinter( hPrinter );
     EndDocPrinter( hPrinter );
     ClosePrinter( hPrinter );
     Exit;
   end;

   if not EndPagePrinter( hPrinter ) then begin
     EndDocPrinter( hPrinter );
     ClosePrinter( hPrinter );
     Exit;
   end;

   if not EndDocPrinter( hPrinter ) then begin
     ClosePrinter( hPrinter );
     Exit;
   end;

   ClosePrinter( hPrinter );

   Result:=dwBytesWritten = dwCount;
End;

function SwitchPrinter(const APrtName : string):string;
var
   Device,
     Driver,
     Port: array[0..255] of Char;
   DevMode: THandle;
begin
   with Printer do
   begin
     PrinterIndex := Printers.IndexOf(APrtName);
     GetPrinter(Device, Driver, Port, DevMode);
     SetPrinter(Device, Driver, Port, 0);
     result:=Printers[printerindex];
   end;
end;

function GetGeneratePulseSequence( m, t1, t2:ansistring ): Ansistring;//hier sagt er missing parameter type
begin
  Result := Esc_p + m + t1 + t2;//incompatible typen string und integer
end;

function GetDefaultGeneratePulseSequence : AnsiString;
begin
  Result := GetGeneratePulseSequence( {m} Lade1, {t1} PulsDauer200ms, {t2} PulsDauer200ms );
end;

procedure Tform1.opendrawer();
Var
    FH:THandle;
    Buff: array[0..5] of char;
    RetW:DWORD;
    port:string;
    cmd:string;
    acmd:ansistring;
    p:pansichar;
begin
   acmd:=getDefaultGeneratePulseSequence;// hier der anstring aus der Function
   p := PAnsiChar( acmd);
   p:=StrPCopy(p,acmd);
   switchprinter('CognitiveTPG Receipt'); //Druckername, so wie er in Windows angezeigt wird
   rawdatatoprinter(pwidechar('CognitiveTPG Receipt'),pbyte(p),length(acmd));
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
opendrawer;
end;
jedoch meckert er hier
rawdatatoprinter(pwidechar('CognitiveTPG Receipt'),pbyte(p),length(acmd)); invalid typcast pbyte(p)
  Mit Zitat antworten Zitat