Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Spara och ladda skrivarinställningar från registret
|
Kategori: Skrivare
Inlagt: 2002-12-20
Läst: 1485
Inlagt av: Staffan Berg
|
Beskrivning |
Detta exempel gör det möjligt att spara respektive ladda skrivarinställningar i registret.
|
Kod |
uses
printers, registry;
{$R *.dfm}
procedure SaveCurrentPrinterSettings( reg: TRegistry );
var
Device, Driver, Port: array[0..80] of Char;
DevMode: THandle;
pDevmode: PDeviceMode;
begin
Printer.GetPrinter(Device, Driver, Port, DevMode);
if Devmode <> 0 then
begin
//lock it to get pointer to DEVMODE record
pDevMode := GlobalLock( Devmode );
if pDevmode <> Nil then
try
reg.WriteBinaryData(device, pDevmode^, sizeof( TDevicemode ));
finally
{unlock devmode handle.}
GlobalUnlock( Devmode );
end;
end;
end;
procedure LoadCurrentPrinterSettings( reg: TRegistry );
var
Device, Driver, Port: array[0..80] of Char;
DevMode: THandle;
pDevmode: PDeviceMode;
begin
Printer.GetPrinter(Device, Driver, Port, DevMode);
if Devmode <> 0 then
begin
//lock it to get pointer to DEVMODE record
pDevMode := GlobalLock( Devmode );
If pDevmode <> Nil then
try
reg.ReadBinaryData(device, pDevmode^, sizeof( TDevicemode ));
finally
//unlock devmode handle.
GlobalUnlock( Devmode );
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
reg: TRegistry;
begin
reg:= TRegistry.Create( KEY_READ OR KEY_WRITE );
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('Software\PB\Test', true) then
try
SaveCurrentPrinterSettings( reg );
finally
reg.CloseKey;
end
finally
reg.free
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
reg: TRegistry;
begin
reg:= TRegistry.Create( KEY_READ );
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('Software\PB\Test', false) then
try
LoadCurrentPrinterSettings( reg );
finally
reg.CloseKey;
end
finally
reg.free
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
printdialog1.execute
end;
|
|
|