AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Textdatei mit vorangestellten Steuercodes
Thema durchsuchen
Ansicht
Themen-Optionen

Textdatei mit vorangestellten Steuercodes

Ein Thema von waldforest · begonnen am 8. Jul 2015 · letzter Beitrag vom 9. Jul 2015
 
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#13

AW: Textdatei mit vorangestellten Steuercodes

  Alt 9. Jul 2015, 10:33
Hallo,
und wie wäre dies #9 umzusetzen ?

Denn vielleicht ist dieses das eigentliche Problem zwischen Windows XP (treiber) und Win 7 (treiber).
Eine Möglichkeit ist die Verwendung von einem StringStream:
Delphi-Quellcode:
var
  MeinTollertext : string;

TStringStream.Create( MeinTollerText, TEncoding.ANSI, False );
oder man holt sich die Bytes vom Encoding
Delphi-Quellcode:
var
  MeinTollerText : string;

TEncoding.ANSI.GetBytes( MeinTollerText );
Und für die Escape-Sequenzen würde ich mir eine kleine Unit schreiben und diese auch nach Bedarf erweitern. Der Code wird dadurch ungemein verständlicher:
Delphi-Quellcode:
// Statt
AppendStringToFile( Chr(27)+'(s18H'+CHR(27)+'(s8V', ... );
// viel besser nachvollziehbar, was hier passieren soll
AppendStringToFile(
  TPCLCodes.PrimaryPitch( 18 ) +
  TPCLCodes.PrimaryHeight( 8 ),
  ... );
und diese Unit würde dann am Anfang so aussehen:
Delphi-Quellcode:
unit PclCodes;

interface

type
  TPCLCodes = class
  public type
    TPrimarySpacing = ( Fixed, Proportional );
  private const
    ESC = #27;
  public const
    PrimarySpacing_Fixed = ESC + '(s0P';
    PrimarySpacing_Proportional = ESC + '(s1P';

    PrimarySmbolSet_ASCII = ESC + '(0U';
    PrimarySmbolSet_Legal = ESC + '(1U';
    PrimarySymbolSet_Win_3_1_Latin1 = ESC + '(9U';
    PrimarySymbolSet_PC_8 = ESC + '(10U';
    PrimarySymbolSet_PC_8_DN = ESC + '(11U';
    PrimarySymbolSet_PC_850 = ESC + '(12U';
    PrimarySymbolSet_Pi_FONT = ESC + '(15U';
    PrimarySymbolSet_PC_852 = ESC + '(17U';
    PrimarySymbolSet_ANSI = ESC + '(19U';

    PrimarySymbolSet_ISO_80 = ESC + '(0D';
    PrimarySmbolSet_ISO_8859_1 = ESC + '(0N';
    PrimarySmbolSet_ISO_8859_2 = ESC + '(2N';
    PrimarySmbolSet_ISO_8859_9 = ESC + '(5N';
    PrimarySymbolSet_Latin1 = PrimarySmbolSet_ISO_8859_1;
    PrimarySymbolSet_Latin2 = PrimarySmbolSet_ISO_8859_2;
    PrimarySymbolSet_Latin5 = PrimarySmbolSet_ISO_8859_9;

    PrimarySymbolSet_Latin1_ANSI = PrimarySymbolSet_ANSI;
  private const
    PrimaryPitchFormat = ESC + '(s%dH';
    PrimaryHeightFormat = ESC + '(s%dV';

    PrimarySpacingValues: array [ TPrimarySpacing ] of string = ( PrimarySpacing_Fixed, PrimarySpacing_Proportional );
  public
    class function PrimarySpacing( Value: TPrimarySpacing ): string;
    class function PrimaryPitch( CharactersPerInch: Integer ): string;
    class function PrimaryHeight( Points: Integer ): string;
  end;

implementation

uses
  System.SysUtils;

{ TPCLCodes }

class function TPCLCodes.PrimaryHeight( Points: Integer ): string;
begin
  Result := Format( PrimaryHeightFormat, [ Points ] );
end;

class function TPCLCodes.PrimaryPitch( CharactersPerInch: Integer ): string;
begin
  Result := Format( PrimaryPitchFormat, [ CharactersPerInch ] );
end;

class function TPCLCodes.PrimarySpacing( Value: TPrimarySpacing ): string;
begin
  Result := PrimarySpacingValues[ Value ];
end;

end.
Ach ja, die Prozedur/Methode würde ich etwas anders benennen:
Delphi-Quellcode:
procedure CombineStreams( ASource1, ASource2, ATarget: TStream );
begin
  ATarget.CopyFrom( ASource1, ASource1.Size );
  ATarget.CopyFrom( ASource2, ASource2.Size );
end;

procedure PrepareFileToPrint( ASourceFileName, ATargetFileName, APrefixStr: string );
var
  LSource1, LSource2, LTarget: TStream;
begin
  LSource1 := nil;
  LSource2 := nil;
  LTarget := nil;
  try
    LSource1 := TStringStream.Create( APrefixStr, TEncoding.ANSI, False );
    LSource2 := TFileStream.Create( ASourceFileName, fmOpenRead or fmShareDenyWrite );
    LTarget := TFileStream.Create( ATargetFileName, fmCreate or fmShareDenyRead );

    CombineStreams( LSource1, LSource2, LTarget );
  finally
    LSource1.Free;
    LSource2.Free;
    LTarget.Free;
  end;
end;

procedure TForm1.Button3Click( Sender: TObject );
begin
  PrepareFileToPrint(
  {} 'test.txt',
  {} 'print.txt',
  {} TPCLCodes.PrimaryPitch( 18 ) + TPCLCodes.PrimaryHeight( 8 ) );
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz