1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
{ TPrinterSetupDialog }
function TPrinterSetupDialog.Execute: Boolean;
Var Dlg : Tdlgpropertiesprinter;
begin
Dlg:=TdlgPropertiesPrinter.Create(nil);
try
if (Title='') then
begin
if Printer<>nil then
Dlg.Caption := Printer.PrinterName;
end else
Dlg.Caption := Title;
Result:=(Dlg.ShowModal=mrOk);
if Result then
Dlg.InitProperties;
finally
Dlg.Free;
end;
end;
function GetNumber(FromLeft: boolean; s:ansistring; aDefault: Integer): Integer;
var
i: Integer;
res: string;
begin
if FromLeft then
i := 1
else
i := Length(s);
Res := '';
while (i>0)and(i<=Length(s)) do
begin
if s[i] in ['0'..'9'] then begin
if Fromleft then
Res:=Res+S[i]
else
Res:=S[i]+Res;
end else begin
if Res<>'' then
break;
end;
if FromLeft then
Inc(i)
else
Dec(i);
end;
Result := StrToIntDef(Res, aDefault);
end;
{ TPrintDialog }
function TPrintDialog.Execute: Boolean;
Var
Dlg : TdlgSelectPrinter;
i : Integer;
begin
Dlg:=TdlgSelectPrinter.Create(nil);
Dlg.Options := Self.Options;
Dlg.PrintRange := Self.PrintRange;
Dlg.cbCollate.Checked := Self.Collate;
Dlg.edCopies.Value := Self.Copies;
if Title<>'' then
Dlg.Caption := Title
else
Dlg.Caption := DefaultTitle;
if FromPage<1 then FromPage:=1;
if ToPage<FromPage then ToPage:=FromPage;
Dlg.edRange.Text := IntToStr(Self.FromPage) +'-'+ IntToStr(Self.ToPage);
case Dlg.PrintRange of
prAllPages: Dlg.rbAllPage.Checked := True;
prSelection: Dlg.rbSelection.Checked := True;
prPageNums: Dlg.rbRange.Checked := True;
prCurrentPage: Dlg.rbCurrentPage.Checked := True;
end;
try
Dlg.btnPreview.Visible:=False;
Result:=(Dlg.ShowModal=mrOk);
if Result then begin
// TDlgSelectPrinter will setup directoy cups printer options
// yet, TPrintDialog should return information about user choice
// modifying fields accordingly.
self.PrintRange:=dlg.PrintRange;
self.Collate := dlg.cbCollate.Checked;
self.Copies := dlg.edCopies.Value;
// Page range. This migth get really complex because it's free enty
// textbox. To fill FromPage and ToPage we will use some
// simple rules.
i := pos('-', Dlg.edRange.Text);
if i<>0 then begin
FromPage := GetNumber(False, copy(Dlg.edRange.Text, 1, i-1), FromPage);
ToPage := GetNumber(True, copy(Dlg.edRange.Text, i+1, 255), ToPage);
if ToPage<FromPage then begin
i := ToPage;
ToPage := FromPage;
FromPage := i;
end;
end else begin
Self.FromPage := GetNumber(True, copy(Dlg.edRange.Text, i+1, 255), Self.FromPage);
Self.ToPage := Self.FromPage;
end;
end;
finally
Dlg.Free;
end;
end;
{ TPrintDialog }
function TPageSetupDialog.Execute: Boolean;
var
Dlg: TDlgPageSetup;
begin
Dlg:=TdlgPageSetup.Create(nil);
if Title<>'' then
Dlg.Caption:=Title
else
Dlg.Caption:=DefaultTitle;
try
Result:=(Dlg.ShowModal=mrOk);
if Result then begin
end;
finally
Dlg.Free;
end;
end;
|