Autor Beitrag
mcbain
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60
Erhaltene Danke: 1



BeitragVerfasst: Mi 20.07.11 15:22 
Hallo,
der Titel sagt schon alles. Ich möchte einem Zebra p430i (einen Ausweisdrucker + Codierer) Escapesequenzen schicken.

Das ganze funktioniert auch in Delphi 7 wunderbar. Der Drucker macht das was ich ihm Befehle. Verwende ich jedoch den gleichen Code in Delphi 2010, so wird zwar eine Karte eingezogen und bedruckt, aber er versteht irgendwie nicht welche Steuer-Sequenz ich ihm mitgeteilt habe. Er druckt immer das gleiche, eine leere Karte.

Ich verwende bei beiden Versionen folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
TPassThroughData = record
      nLen: Word;
      Data: array[0..255of Byte;

...

procedure TForm2.btn2Click(Sender: TObject);
  procedure PrintText(s: AnsiString);
  var
    PTBlock: TPassThroughData;
  begin
    PTBlock.nLen := Length(s);
    StrPCopy(@PTBlock.Data, s);
    Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil);
  end;

begin

  Printer.BeginDoc;
  PrintText(chr(27)+AnsiString('MC')+chr(13));
  Printer.EndDoc;

end;


Kann mir jemand sagen warum es unter D2010 nicht funktioniert aber unter D7? Dachte es läge evtl. an UTF8, da D7 ja noch nicht UTF8 hatte. Ansistring hat aber auch nix gebracht irgendwie....

Wäre nett, wenn mir jemand einen Tip geben könnte woran das liegen könnte.
Vielen Dank.
mc


Moderiert von user profile iconNarses: Topic aus Windows API verschoben am Mi 20.07.2011 um 15:44
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 20.07.11 15:44 
Moin!

user profile iconmcbain hat folgendes geschrieben Zum zitierten Posting springen:
Kann mir jemand sagen warum es unter D2010 nicht funktioniert aber unter D7?
Char und AnsiChar sind ab D2k9 auch nicht mehr das Gleiche! :les: Also vielleicht mal so probieren? :idea:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
const
  EscapeSeq: Ansistring = #27'MC'#13;
begin
  PrintText(EscapeSeq);
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
mcbain Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 60
Erhaltene Danke: 1



BeitragVerfasst: Mi 20.07.11 16:13 
Danke für die schnelle Antwort, leider hat das auch nichts geholfen.
Ich habe aber nun meine Lösung gefunden. Hier wurde das Problem besprochen: forums.embarcadero.c...spa?messageID=166484

Folgender Code funktioniert auch bei D2010:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm2.btn1Click(Sender: TObject);
var
s: AnsiString;

  procedure RAWPrint(PrinterName, DocumentTitle, DocumentData: string);
  var
  hPrinter: DWord;
  DocInfo: TDocInfo1;
  dwBytesWritten: DWord;
  DocumentDataAnsi: AnsiString;
  begin
    OpenPrinter(PChar(PrinterName), hPrinter, nil);
    DocInfo.pOutputFile:= nil;
    DocInfo.pDatatype:= 'RAW';
    DocInfo.pDocName:= PChar(DocumentTitle);
    StartDocPrinter(hPrinter, 1, @DocInfo);
    StartPagePrinter(hPrinter);
    DocumentDataAnsi := DocumentData;

    if Length(DocumentDataAnsi) > 0 then
       WritePrinter(hPrinter, @DocumentDataAnsi[1],Length(DocumentDataAnsi),dwBytesWritten);

    EndPagePrinter(hPrinter);
    EndDocPrinter(hPrinter);
    ClosePrinter(hPrinter);
  end;
begin
s := chr(27)+AnsiString('MC')+chr(13);

RAWPrint('Druckername''jobtitle', s); // "Label printer" is the name of the printer

end;


Vielen Dank nochmal.
Viele Grüße
mc