How to select a printer installed in Windows?

In system configurations it is very common to have to inform
a standard printer to automate some task.
Right. We can manually enter the printer share name
or we can create a way for the user to choose easily.
Using TPrinterDialog, the system will make use of Windows’ own search!
Let’s go to the code!
I will put the whole unit to facilitate understanding.
unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm2 = class(TForm) Button1: TButton; PrintDialog1: TPrintDialog; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2 : TForm2 ; implementation {$R *.dfm} uses {Very important to declare this unit} Vcl . Printers ; procedure TForm2 . Button1Click ( Sender : TObject ) ; begin if PrintDialog1 . Run then begin // Displaying the selected printer !!! ShowMessage ( Printer . Printers [ Printer . PrinterIndex ] ) ; end ; end ; end.
So we can see at the click of a button the printer selects, making it
much easier for the end user.