The following unit shows how you can use the Printer object to obtain information via your own dialog. This example simply changes the current printer, but there is lots of information in the Printer class you can extract/change via a customised dialog. Here the function PrinterChangedTo returns the name of the new current printer, or an empty string if the current printer has not been changed. This (or a more capable adaptation) could easily be turned into a dialog component if preferred.
unit simple_print_dlg;
{$mode objfpc}{$H+}
interface
uses
Forms, Controls, StdCtrls, ButtonPanel, Printers;
type
TfrmPrintDlg = class(TForm)
BPanel: TButtonPanel;
CBPrinters: TComboBox;
gbPrinter: TGroupBox;
LName: TLabel;
end;
function PrinterChangedToDlg: string;
implementation
function PrinterChangedToDlg: string;
var
frm: TfrmPrintDlg;
begin
Result:= '';
if not Assigned(Printer) then Exit;
if Printer.Printers.Count=0 then Exit;
frm:= TfrmPrintDlg.Create(nil);
try
frm.CBPrinters.Items.Assign(Printer.Printers);
frm.CBPrinters.ItemIndex:=0;
if frm.ShowModal = mrOK then
if (frm.CBPrinters.ItemIndex>0) then
begin
Printer.SetPrinter(Printer.Printers[frm.CBPrinters.ItemIndex]);
Result:= Printer.Printers[frm.CBPrinters.ItemIndex];
end;
finally
frm.Free;
end;
end;
{$R *.lfm}
end.
The .lfm is as follows:
object frmPrintDlg: TfrmPrintDlg
Left = 254
Height = 173
Top = 152
Width = 320
Caption = 'Printer Information'
ClientHeight = 173
ClientWidth = 320
LCLVersion = '1.0.6.0'
object gbPrinter: TGroupBox
Left = 12
Height = 113
Top = 10
Width = 300
Caption = 'Printer'
ClientHeight = 91
ClientWidth = 296
TabOrder = 0
object LName: TLabel
Left = 10
Height = 21
Top = 10
Width = 91
Caption = 'Printer Name:'
ParentColor = False
end
object CBPrinters: TComboBox
Left = 10
Height = 28
Top = 44
Width = 276
ItemHeight = 20
ParentShowHint = False
Style = csDropDownList
TabOrder = 0
end
end
object BPanel: TButtonPanel
Left = 6
Height = 38
Top = 129
Width = 308
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 1
ShowButtons = [pbOK, pbCancel]
end
end