Einzelnen Beitrag anzeigen

Pfl

Registriert seit: 5. Jun 2012
Ort: Berlin
65 Beiträge
 
Delphi XE6 Architect
 
#12

AW: Hardware ansteuern

  Alt 23. Okt 2012, 21:14
Vielen Dank, Bummi. Ich hab den Fehler zwar behoben, leider will der dämliche Drucker nicht die Lade öffnen.

Hier ist der komplette Source:

Delphi-Quellcode:
unit Unit9;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, ComCtrls, ButtonWithColor, Registry, IniFiles,
  OleServer, CmAdmCtl, Printers, cyBaseButton, cyBitBtn;

type
  TForm9 = class(TForm)
    Image1: TImage;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    ComboBox1: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    Label3: TLabel;
    Edit1: TEdit;
    Label4: TLabel;
    Edit2: TEdit;
    Label5: TLabel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    Label6: TLabel;
    UpDown1: TUpDown;
    PrinterSetupDialog1: TPrinterSetupDialog;
    PrintDialog1: TPrintDialog;
    Edit3: TEdit;
    ComboBox4: TComboBox;
    Label7: TLabel;
    BitBtn1: TBitBtn;
    ComboBox5: TComboBox;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    ComboBox6: TComboBox;
    Edit4: TEdit;
    Edit5: TEdit;
    ComboBox7: TComboBox;
    Label11: TLabel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    ComboBox8: TComboBox;
    Label12: TLabel;
    GroupBox5: TGroupBox;
    CheckBox5: TCheckBox;
    COMAdminCatalog1: TCOMAdminCatalog;
    RichEdit1: TRichEdit;
    cyBitBtn1: TcyBitBtn;
    procedure SpeedButton2Click(Sender: TObject);

    procedure CheckBox5Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure cyBitBtn1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);

  private
    { Private-Deklarationen }
      IniFile : TMemIniFile;
  public
    { Public-Deklarationen }
  end;
  function SendEscapeToPrinter(const PrinterName: String; Const S: AnsiString): Boolean;
var
  Form9: TForm9;
  Reg: TRegistry;
  Ini : TIniFile;
  p: TPrinter;
implementation

{$R *.dfm}

procedure TForm9.BitBtn1Click(Sender: TObject);
begin


  if PrintDialog1.Execute then
  begin
    printer.BeginDoc;
  printer.NewPage;
    printer.EndDoc;
    Application.MessageBox('Dokument wurde in Auftrag gegeben.','',mb_ICONINFORMATION or mb_OK);
  end;
end;

procedure TForm9.BitBtn2Click(Sender: TObject);
begin
WriteLn ('Hallo Text');
  WriteLn ('Jetzt wird abgeschnitten');
  Write (#029#086#065#010);

end;

procedure TForm9.BitBtn3Click(Sender: TObject);
begin

if SendEscapeToPrinter(ComboBox1.Text,Combobox7.Text) then
Application.MessageBox('Wurde die Lade geöffnet?','Impulstest Kassenlade',mb_ICONQUESTION or mb_YESNO);

end;



procedure TForm9.CheckBox5Click(Sender: TObject);
begin
  if CheckBox1.Checked=true then
  begin
  cyBitBtn1.Enabled:=true;
  end;
end;

procedure TForm9.cyBitBtn1Click(Sender: TObject);
begin
   Application.MessageBox('Möchten Sie ApoPlus 2010 wirklich in den Autostart-Ordner des Systems schreiben? Falls Ja, muss das System neu gestartet werden','Registry-Eintrag Autostart',mb_ICONWARNING or mb_YESNO);

end;

procedure TForm9.FormActivate(Sender: TObject);
var ini : TiniFile;
begin

  Ini:=TIniFile.Create('C:\Settings\Control.ini');
  try
    Combobox1.Text := Ini.ReadString('Printer', 'Output','') ;
    ComboBox2.Text := Ini.ReadString('Printer', 'Interface','') ;
    ComboBox3.Text := Ini.ReadString('Printer', 'Hersteller','') ;
    //Ini.ReadString('Printer', 'Anzahl', Edit1.Text);
    //Ini.ReadString('Printer', 'Speed', Edit2.Text);
    IF Ini.ReadString('Printer', 'AutoCutEnabled','') = 'YES'
    then CheckBox1.Checked := true
    else CheckBox1.Checked := false;


    Edit3.Text := Ini.ReadString('Printer', 'Breite','');

    //ComboBox4.Text := Ini.WriteString('Printer', 'Format' );

    if Ini.ReadString('Display', 'Enabled','') = 'YES'
    then CheckBox2.Checked := true
    else CheckBox2.checked := false;


    //ComboBox5.Text := Ini.WriteString('Display', 'Interface' );
    //ComboBox6.Text := Ini.WriteString('Display', 'Steuerzeichen');
    //Edit4.Text + Edit5.Text := Ini.WriteString('Display', 'Text' );

    //if CheckBox4.Checked
    //then Ini.WriteString('POS', 'Enabled', 'YES')
    //else Ini.WriteString('POS','Enabled','NO');

    //Ini.WriteString('POS', 'Algorithmus', ComboBox7.Text);

    //if CheckBox3.Checked
    //then Ini.WriteString('EC', 'Enabled', 'YES')
    //else Ini.WriteString('EC', 'Enabled', 'NO');

    //ComboBox8.Text := Ini.WriteString('EC','Interface');
  finally
    Ini.Free;

     p := TPrinter.Create;
  try
    ComboBox1.Items.Assign(p.Printers)
  finally
    p.Free;
  end;
end;
end;


procedure TForm9.SpeedButton1Click(Sender: TObject);

begin
  Ini:=TIniFile.Create('C:\Settings\Control.ini');
  try
    Ini.WriteString('Printer', 'Output', Combobox1.Text);
    Ini.WriteString('Printer', 'Interface', ComboBox2.Text);
    Ini.WriteString('Printer', 'Hersteller', ComboBox3.Text);
    Ini.WriteString('Printer', 'Anzahl', Edit1.Text);
    Ini.WriteString('Printer', 'Speed', Edit2.Text);
    if CheckBox1.Checked
    then Ini.WriteString('Printer', 'AutoCutEnabled', 'YES')
    else Ini.WriteString('Printer', 'AutoCutEnabled', 'NO');


    Ini.WriteString('Printer', 'Breite', Edit3.Text);
    Ini.WriteString('Printer', 'Format', ComboBox4.Text);

    if CheckBox2.Checked
    then Ini.WriteString('Display', 'Enabled', 'YES')
    else Ini.WriteString('Display', 'Enabled', 'NO');

    Ini.WriteString('Display', 'Interface', ComboBox5.Text);
    Ini.WriteString('Display', 'Steuerzeichen', ComboBox6.Text);
    Ini.WriteString('Display', 'Text', Edit4.Text + Edit5.Text);

    if CheckBox4.Checked
    then Ini.WriteString('POS', 'Enabled', 'YES')
    else Ini.WriteString('POS','Enabled','NO');

    Ini.WriteString('POS', 'Algorithmus', ComboBox7.Text);

    if CheckBox3.Checked
    then Ini.WriteString('EC', 'Enabled', 'YES')
    else Ini.WriteString('EC', 'Enabled', 'NO');

    Ini.WriteString('EC','Interface',ComboBox8.Text);
  finally
    Ini.Free;
  Application.MessageBox('Ihre Änderungen wurden übernommen. Eventuell muss das Programmm neu gestartet werden. Übername in C:\Settings\.','Änderungen gesichert',mb_ICONINFORMATION or mb_OK);
  Form9.Close;
end;
end;
procedure TForm9.SpeedButton2Click(Sender: TObject);
begin
  if Application.MessageBox('Sind Sie sicher, dass Sie abbrechen wollen?', 'Abbruch bestätigen', MB_ICONQUESTION or MB_YESNOCANCEL) = IDYES
  then close;
end;

function SendEscapeToPrinter(const PrinterName: String; Const S: AnsiString): Boolean;
type
  TPrnBuffRec = record
    bufflength: Word;
    Buff_1: array [0 .. 255] of AnsiChar;
  end;
var
  Buff: TPrnBuffRec;
  TestInt: Integer;
  OldIndex: Integer;
begin
  OldIndex := Printer.PrinterIndex;
  try
    Result := Printer.printers.IndexOf(PrinterName) > -1;
    Printer.PrinterIndex := Printer.printers.IndexOf(PrinterName);
    Printer.BeginDoc;
    TestInt := PassThrough;
    if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TestInt), @TestInt, nil) > 0 then
    begin
      StrPCopy(Buff.Buff_1, S);
      Buff.bufflength := StrLen(Buff.Buff_1);
      Escape(Printer.Canvas.Handle, PassThrough, 0, @Buff, nil);
      Result := True;
      Printer.EndDoc;
    end
    else
      Result := False;
  finally
    Printer.PrinterIndex := OldIndex;
  end;
end;
end.
Hat jemand eine Idee? Erst mal vielen Dank für die bisherigen Antworten!
Friedrich
  Mit Zitat antworten Zitat