Arsip: Ubah Printer Default di Quick Report

 
user image
more 12 years ago

yoga_gtg

Mau Nanya di komputer saya ada dua buah program delphi yang masing2 menggunakan Report pada Printer jenis yang berbeda 1. LX 300+ 2. TM_T88III padahal kedua program tersebut otomatis ngeprint di default printer untuk reportnya. saya menggunakan komponen Quick report bawaan delphi 7. jadi, pertanyaan saya gimana cara ngubah settingan default printer saya melalui script di delphi agar kedua program tersebut bisa berjalan bersama-sama terima kasih
user image
more 12 years ago

madi


uses
  Printers, Messages;
function GetDefaultPrinter: string;
var
  ResStr: array of Char;
begin
  GetProfileString('Windows', 'device', '', ResStr, 255);
  Result := StrPas(ResStr);
end;
procedure SetDefaultPrinter1(NewDefPrinter: string);
var
  ResStr: array of Char;
begin
  StrPCopy(ResStr, NewdefPrinter);
  WriteProfileString('windows', 'device', ResStr);
  StrCopy(ResStr, 'windows');
  SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@ResStr));
end;
procedure SetDefaultPrinter2(PrinterName: string);
var
  I: Integer;
  Device: PChar;
  Driver: PChar;
  Port: PChar;
  HdeviceMode: THandle;
  aPrinter: TPrinter;
begin
  Printer.PrinterIndex := -1;
  GetMem(Device, 255);
  GetMem(Driver, 255);
  GetMem(Port, 255);
  aPrinter := TPrinter.Create;
  try
    for I := 0 to Printer.Printers.Count - 1 do
    begin
      if Printer.Printers = PrinterName then
      begin
        aprinter.PrinterIndex := i;
        aPrinter.getprinter(device, driver, port, HdeviceMode);
        StrCat(Device, ',');
        StrCat(Device, Driver);
        StrCat(Device, Port);
        WriteProfileString('windows', 'device', Device);
        StrCopy(Device, 'windows');
        SendMessage(HWND_BROADCAST, WM_WININICHANGE,
          0, Longint(@Device));
      end;
    end;
  finally
    aPrinter.Free;
  end;
  FreeMem(Device, 255);
  FreeMem(Driver, 255);
  FreeMem(Port, 255);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := GetDefaultPrinter2;
end;
//Fill the combobox with all available printers
procedure TForm1.FormCreate(Sender: TObject);
begin
  Combobox1.Items.Clear;
  Combobox1.Items.AddStrings(Printer.Printers);
end;
//Set the selected printer in the combobox as default printer
procedure TForm1.Button2Click(Sender: TObject);
begin
  SetDefaultPrinter(Combobox1.Text);
end;
:shock:
user image
more 12 years ago

nizar

Wah, ternyata pertanyaan saya tujuh tahun yang lalu sebagian ada jawabannya di sini. Repot ngatur printernya, nggak tahu tanya ke siapa, sudah diubah setingnya tapi pas ngeperint terus saja pake seting default, padahal kalo cetak nggak pake Quick report ya langsung sesuai perubahan, terpaksa dech coding sendiri nggak pake Quick report.
user image
more 12 years ago

yoga_gtg

waduh mas madi kok saya coba sintaxnya ad yg error mas di line SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@ResStr)); error undeclared identifier. gimana tuh mas oh ya sebelumnya mau nanya dengan scrip tsb apakah kedua program tetap bs berjalan padahal kedua program tersebut mempunyai default printer yang berbeda dan berjalan bersamaan please help me lagi ngejar deadline nh
user image
more 12 years ago

reminder2k1

kenapa ga pake printdialog aja??? Asumsikan pada form ada TQRReport, TQRPreview, TPrintDialog... Nah sekarang tgl buat aja scipt buat tombol printnya:

uses Printers;
procedure TFrCetak.AcPrintSetupExecute(Sender: TObject);
begin
     QuickRep1.ShowProgress:=true;
     PrintDialog.FromPage := 1;
     PrintDialog.ToPage := QRPreview1.QRPrinter.PageCount;
     PrintDialog.MinPage := 1;
     PrintDialog.MaxPage := QRPreview1.QRPrinter.PageCount;
     if PrintDialog.Execute then begin
        If QRPreview1.QRPrinter.Master is TQuickRep then begin
           With TQuickRep(QRPreview1.QRPrinter.Master) do begin
                printersettings.FirstPage:=PrintDialog.FromPage;
                printersettings.LastPage:=PrintDialog.ToPage;
                printersettings.Copies:=PrintDialog.Copies;
                Printersettings.PrinterIndex:=Printers.Printer.PrinterIndex;
                QRPreview1.QRPrinter.Print;
           end;
        end;
     end;
end;
Met berexplorasi ya??? :mrgreen:
user image
more 12 years ago

madi

kenapa ga pake printdialog aja???
klo pake gtoan keliatan kurang profesional bro ...:D
user image
more 12 years ago

reminder2k1

@madi: klo pake gtoan keliatan kurang profesional bro ...:D
Hehehehehe... Profesional dilihat dari itunya ya??? xixixixixixi Terserah deh... Memanfaatkan apa yg ada, klo terpaksa harus maen hard coding, ya baru maen hard coding... xixixixixixi Yang penting apa yg kita terpenuhi bro... :D Banyak jalan menuju Roma bro... :mrgreen:
user image
more 12 years ago

jimbot

adem..adem...adem xixixixi....
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com