Issue #1482: add printlist dialog, yet non-functional due to undefined EnablePrint constant

This commit is contained in:
Ansgar Becker
2025-03-04 16:39:40 +01:00
parent 005f86243c
commit a4dc12c517
4 changed files with 202 additions and 2 deletions

View File

@ -29,6 +29,9 @@
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="Printer4Lazarus"/>
</Item>
<Item>
<PackageName Value="laz.virtualtreeview_package"/>
</Item>
@ -102,6 +105,7 @@
<Filename Value="source\loginform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="frmLogin"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit>
<Unit>
@ -115,6 +119,13 @@
<Filename Value="source\const.inc"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="source\printlist.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="printlistForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -11,12 +11,12 @@ uses
{$ENDIF}
Interfaces, // this includes the LCL widgetset
SysUtils,
Forms,
Forms, printer4lazarus,
{ you can add units after this }
main, apphelpers, dbconnection, { gnugettext,}
dbstructures, dbstructures.mysql, About, generic_types,
dbstructures.interbase, dbstructures.mssql, dbstructures.postgresql,
dbstructures.sqlite, change_password, loginform
dbstructures.sqlite, change_password, loginform {, printlist (EnablePrint not defined) }
;
{$R *.res}

82
source/printlist.lfm Normal file
View File

@ -0,0 +1,82 @@
object printlistForm: TprintlistForm
Left = 521
Height = 115
Top = 91
Width = 471
BorderStyle = bsDialog
Caption = 'Print List...'
ClientHeight = 115
ClientWidth = 471
Color = clBtnFace
DesignTimePPI = 120
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Tahoma'
OnShow = FormShow
Position = poMainFormCenter
object lblSelect: TLabel
Left = 10
Height = 18
Top = 14
Width = 89
Caption = '&Select printer:'
FocusControl = comboPrinters
end
object comboPrinters: TComboBox
Left = 102
Height = 26
Top = 10
Width = 258
ItemHeight = 18
Style = csDropDownList
TabOrder = 0
OnChange = comboPrintersChange
end
object btnConfigure: TButton
Left = 368
Height = 31
Top = 10
Width = 94
Caption = 'Configure'
TabOrder = 1
OnClick = btnConfigureClick
end
object btnCancel: TButton
Left = 367
Height = 31
Top = 74
Width = 94
Anchors = [akRight, akBottom]
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 3
end
object btnPrint: TButton
Left = 266
Height = 31
Top = 74
Width = 94
Anchors = [akRight, akBottom]
Caption = 'Print'
Default = True
ModalResult = 1
TabOrder = 2
OnClick = btnPrintClick
end
object chkPrintHeader: TCheckBox
Left = 102
Height = 22
Top = 45
Width = 258
Anchors = [akTop, akLeft, akRight]
Caption = 'Print column headers'
Checked = True
State = cbChecked
TabOrder = 4
end
object PrinterSetup: TPrinterSetupDialog
Left = 10
Top = 40
end
end

107
source/printlist.pas Normal file
View File

@ -0,0 +1,107 @@
unit printlist;
{$mode delphi}{$H+}
// -------------------------------------
// Print TListView-Content
// -------------------------------------
interface
uses
Classes, Controls, Forms, Dialogs, StdCtrls, Printers, laz.VirtualTrees,
PrintersDlgs;
type
{ TprintlistForm }
TprintlistForm = class(TForm)
comboPrinters: TComboBox;
btnConfigure: TButton;
btnCancel: TButton;
btnPrint: TButton;
PrinterSetup: TPrinterSetupDialog;
lblSelect: TLabel;
chkPrintHeader: TCheckBox;
procedure btnConfigureClick(Sender: TObject);
procedure btnPrintClick(Sender: TObject);
procedure comboPrintersChange(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
uses main, apphelpers, {table_editor, }dbconnection;
{$R *.lfm}
procedure TprintlistForm.FormShow(Sender: TObject);
begin
// show!
Screen.Cursor := crHourGlass;
comboPrinters.Items := Printer.printers;
comboPrinters.ItemIndex := Printer.printerIndex;
Screen.Cursor := crDefault;
end;
procedure TprintlistForm.btnConfigureClick(Sender: TObject);
begin
Screen.Cursor := crHourglass;
printerSetup.Execute;
comboPrinters.ItemIndex := Printer.PrinterIndex;
Screen.Cursor := crDefault;
end;
procedure TprintlistForm.btnPrintClick(Sender: TObject);
var
list: TVirtualStringTree;
begin
// print!
Screen.Cursor := crHourglass;
list := nil;
// which ListView to print?
case Mainform.PageControlMain.ActivePageIndex of
0: case Mainform.PageControlHost.ActivePageIndex of
0: list := Mainform.ListDatabases;
1: list := Mainform.ListVariables;
2: list := Mainform.ListStatus;
3: list := Mainform.ListProcesses;
else list := Mainform.ListCommandStats;
end;
1: list := Mainform.ListTables;
2: begin
if Assigned(Mainform.ActiveObjectEditor)
and (Mainform.ActiveObjectEditor.DBObject.NodeType = lntTable)
and Mainform.ActiveObjectEditor.Visible then
{list := (Mainform.ActiveObjectEditor as TfrmTableEditor).listColumns;}
end;
else list := Mainform.ActiveGrid;
end;
if Assigned(list) then
try
list.Print(Printer, chkPrintHeader.Checked);
except
on E:EPrinter do
ErrorDialog(E.Message);
end;
Screen.Cursor := crDefault;
end;
procedure TprintlistForm.comboPrintersChange(Sender: TObject);
begin
// chose printer
Screen.Cursor := crHourglass;
Printer.PrinterIndex := comboPrinters.ItemIndex;
Screen.Cursor := crDefault;
end;
end.