Skip to content

Commit

Permalink
[*] move log to another form, closes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub committed Aug 27, 2021
1 parent fc7cca8 commit 21c861e
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 39 deletions.
5 changes: 1 addition & 4 deletions forms/fmconnect.pas
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
unit fmConnect;

{$MODE Delphi}
{$mode objfpc}{$H+}

interface

Expand Down Expand Up @@ -39,9 +39,6 @@ TfmConnect = class(TForm)

function EditDatabase(ADatabase: TPQConnection): boolean;

var
fmConnect: TfmConnect;

implementation

{$R *.lfm}
Expand Down
28 changes: 28 additions & 0 deletions forms/fmlog.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
object fmLog: TfmLog
Left = 554
Height = 856
Top = 176
Width = 935
Caption = 'Log'
ClientHeight = 856
ClientWidth = 935
DesignTimePPI = 144
LCLVersion = '2.0.12.0'
object mmLog: TMemo
Left = 4
Height = 848
Top = 4
Width = 927
Align = alClient
BorderSpacing.Left = 2
BorderSpacing.Top = 2
BorderSpacing.Right = 2
BorderSpacing.Bottom = 2
BorderSpacing.Around = 2
BorderSpacing.InnerBorder = 2
Font.Name = 'Consolas'
ParentFont = False
ScrollBars = ssVertical
TabOrder = 0
end
end
30 changes: 30 additions & 0 deletions forms/fmlog.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
unit fmLog;

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

{ TfmLog }

TfmLog = class(TForm)
mmLog: TMemo;
private

public

end;

var
LogForm: TfmLog;

implementation

{$R *.lfm}

end.

31 changes: 10 additions & 21 deletions forms/fmmain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object fmMain: TfmMain
TabOrder = 1
object gridTasks: TDBGrid
Left = 2
Height = 222
Height = 531
Top = 42
Width = 1508
Align = alClient
Expand Down Expand Up @@ -107,25 +107,6 @@ object fmMain: TfmMain
OnDrawColumnCell = gridTasksDrawColumnCell
OnSelectEditor = gridTasksSelectEditor
end
object splitDetails: TSplitter
Cursor = crVSplit
Left = 2
Height = 9
Top = 264
Width = 1508
Align = alBottom
ResizeAnchor = akBottom
end
object mmLog: TMemo
Left = 2
Height = 300
Top = 273
Width = 1508
Align = alBottom
ParentFont = False
ScrollBars = ssAutoVertical
TabOrder = 2
end
object toolbarTasks: TToolBar
Left = 2
Height = 40
Expand All @@ -139,7 +120,7 @@ object fmMain: TfmMain
Images = imglToolbars
ParentShowHint = False
ShowHint = True
TabOrder = 3
TabOrder = 1
object btnTaskMoveUp: TToolButton
Left = 1
Top = 0
Expand Down Expand Up @@ -758,6 +739,14 @@ object fmMain: TfmMain
OnClick = miCloseClick
end
end
object miView: TMenuItem
Caption = 'View'
object miLog: TMenuItem
AutoCheck = True
Caption = 'Log'
OnClick = miLogClick
end
end
object miHelp: TMenuItem
Caption = 'Help'
object miAbout: TMenuItem
Expand Down
14 changes: 10 additions & 4 deletions forms/fmmain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ TfmMain = class(TForm)
imglToolbarsDisabled: TImageList;
imglToolbars: TImageList;
imglGrids: TImageList;
miLog: TMenuItem;
miView: TMenuItem;
miConnect: TMenuItem;
mmLog: TMemo;
menuMain: TMainMenu;
miFile: TMenuItem;
miClose: TMenuItem;
Expand All @@ -46,7 +47,6 @@ TfmMain = class(TForm)
pnlChains: TPanel;
pnlDetails: TPanel;
splitChain: TSplitter;
splitDetails: TSplitter;
toolbarChains: TToolBar;
toolbarMain: TToolBar;
btnConnect: TToolButton;
Expand Down Expand Up @@ -90,6 +90,7 @@ TfmMain = class(TForm)
procedure gridTasksSelectEditor(Sender: TObject; Column: TColumn;
var Editor: TWinControl);
procedure miCloseClick(Sender: TObject);
procedure miLogClick(Sender: TObject);
private
FLastColumn: TColumn; //last sorted grid column
public
Expand All @@ -101,7 +102,7 @@ TfmMain = class(TForm)

implementation

uses uDataModule, SQLDB, LCLType, RegExpr;
uses uDataModule, SQLDB, LCLType, RegExpr, fmLog;

{$R *.lfm}

Expand Down Expand Up @@ -214,6 +215,11 @@ procedure TfmMain.miCloseClick(Sender: TObject);
Close();
end;

procedure TfmMain.miLogClick(Sender: TObject);
begin
fmLog.LogForm.Visible := not fmLog.LogForm.Visible;
end;

procedure TfmMain.UpdateSortIndication(ACol: TColumn);
begin
// Remove the sort arrow from the previous column we sorted
Expand Down Expand Up @@ -352,7 +358,7 @@ procedure TfmMain.acConnectClick(Sender: TObject);
dmPgEngine.Connect;
except
on EAbort do
mmLog.Lines.Append('Connection cancelled by the user');
fmLog.LogForm.mmLog.Lines.Append('Connection cancelled by the user');
on E: Exception do
MessageDlg('PostgreSQL Error', E.Message, mtError, [mbOK], 0);
end
Expand Down
21 changes: 16 additions & 5 deletions pg_timetable_gui.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="3">
<RequiredPackages Count="4">
<Item1>
<PackageName Value="LazControls"/>
<PackageName Value="SynEdit"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
<PackageName Value="LazControls"/>
</Item2>
<Item3>
<PackageName Value="LCL"/>
<PackageName Value="FCL"/>
</Item3>
<Item4>
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="8">
<Units Count="9">
<Unit0>
<Filename Value="pg_timetable_gui.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -160,6 +163,14 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="fmConnect"/>
</Unit7>
<Unit8>
<Filename Value="forms\fmlog.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="fmLog"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="fmLog"/>
</Unit8>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
3 changes: 2 additions & 1 deletion pg_timetable_gui.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
lazcontrols,
fmMain, fmConnect,
uDataModule,
uObjects;
uObjects, fmLog;

{$R *.res}

Expand All @@ -18,5 +18,6 @@
Application.Initialize;
Application.CreateForm(TfmMain, MainForm);
Application.CreateForm(TdmPgEngine, dmPgEngine);
Application.CreateForm(TfmLog, LogForm);
Application.Run;
end.
2 changes: 1 addition & 1 deletion udatamodule.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object dmPgEngine: TdmPgEngine
Transaction = transChains
UserName = 'scheduler'
OnLog = PQConnLog
LogEvents = [detParamValue, detActualSQL]
LogEvents = [detPrepare, detExecute, detCommit, detParamValue, detActualSQL]
Left = 105
Top = 312
end
Expand Down
10 changes: 7 additions & 3 deletions udatamodule.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ TdmPgEngine = class(TDataModule)

implementation

uses uObjects, fmMain, fmConnect, Dialogs, UITypes;
uses uObjects, fmMain, fmConnect, Dialogs, UITypes, fmLog;

{$R *.lfm}

{ TdmPgEngine }

procedure TdmPgEngine.PQConnLog(Sender: TSQLConnection;
EventType: TDBEventType; const Msg: String);
const et: array[TDBEventType] of string = ('detCustom', 'detPrepare', 'detExecute',
'detFetch', 'detCommit', 'detRollBack', 'detParamValue', 'detActualSQL');
begin
fmMain.MainForm.mmLog.Lines.Append(Msg);
fmMain.MainForm.mmLog.Lines.Append('----------------------------------------------------');
with fmLog.LogForm.mmLog.Lines do
begin
Append(Format('[%s:] %s' + LineEnding, [et[EventType], Msg]))
end;
end;

procedure TdmPgEngine.PQConnLogin(Sender: TObject; Username, Password: string);
Expand Down

0 comments on commit 21c861e

Please sign in to comment.