Code cosmetic:

* Sanitize main unit from unused variables
* Move global variables to public scope
* Bring public vars into some reasonable order
* Move constants to const.inc, unless dependent from some used VCL unit
This commit is contained in:
Ansgar Becker
2010-01-10 17:11:42 +00:00
parent 51bd13b530
commit 4d47af1e9e
7 changed files with 102 additions and 107 deletions

View File

@ -70,8 +70,8 @@ begin
// Assign text
Caption := 'About '+AppName;
lblAppName.Caption := AppName;
lblAppDescription.Caption := AppDescription;
lblAppVersion.Caption := 'Version '+AppVersion;
lblAppDescription.Caption := Mainform.AppDescription;
lblAppVersion.Caption := 'Version '+Mainform.AppVersion;
FileAge(ParamStr(0), Compiled);
lblAppCompiled.Caption := 'Compiled on: ' + DateTimeToStr(Compiled);
lblAppWebpage.Caption := AppDomain;

View File

@ -269,9 +269,15 @@ const
// Data grid: How many bytes to fetch from data fields that are potentially large.
GRIDMAXDATA: Integer = 256;
// Data grid: How many rows to fetch at a time.
GRIDMAXROWS: Cardinal = 1000;
// The InnoDB folks are raging over the lack of count(*) support
// in the storage engine. To avoid count(*), the first of these
// constants decide how many rows the data area should estimate
// in any table. The second value decides how many percent above the
// number of seen (or simulated) rows the scrollbar should project.
SIMULATE_INITIAL_ROWS = 10000;
SIMULATE_MORE_ROWS = 20;
VTREE_NOTLOADED = 0;
VTREE_LOADED = 1;

View File

@ -846,7 +846,7 @@ begin
else
NodeCount := Grid.RootNodeCount;
EnableProgressBar(NodeCount);
Generator := APPNAME+' '+AppVersion;
Generator := APPNAME+' '+Mainform.AppVersion;
tmp :=
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' + CRLF +
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + CRLF + CRLF +

View File

@ -716,27 +716,20 @@ type
private
ReachedEOT: Boolean;
FDelimiter: String;
viewingdata : Boolean;
EditVariableForm : TfrmEditVariable;
FileNameSessionLog: String;
FileHandleSessionLog: Textfile;
SelectedTableColumns : TTableColumnList;
SelectedTableKeys : TTableKeyList;
SelectedTableForeignKeys : TForeignKeyList;
FilterPanelManuallyOpened : Boolean;
DataGridDB, DataGridTable : String;
PrevTableColWidths : TWideStringList;
DataGridHasChanges : Boolean;
FLastMouseUpOnPageControl: Cardinal;
FLastTabNumberOnMouseUp: Integer;
FLastMouseDownCloseButton: TObject;
DataGridResult : TGridResult;
// Filter text per tab for filter panel
FilterTextVariables, FilterTextStatus, FilterTextProcessList, FilterTextCommandStats,
FilterTextDatabase, FilterTextData: String;
FilterTextVariables: String;
FilterTextStatus: String;
FilterTextProcessList: String;
FilterTextCommandStats: String;
FilterTextDatabase: String;
FilterTextData: String;
PreviousFocusedNode: PVirtualNode;
function GetParamValue(const paramChar: Char; const paramName:
string; var curIdx: Byte; out paramValue: string): Boolean;
function GetParamValue(const paramChar: Char; const paramName: string; var curIdx: Byte; out paramValue: string): Boolean;
procedure SetDelimiter(Value: String);
procedure DisplayRowCountStats(MatchingRows: Int64 = -1);
procedure insertFunction(Sender: TObject);
@ -754,8 +747,14 @@ type
procedure DatabaseChanged(Database: String);
public
Connection: TMySQLConnection;
cancelling: Boolean;
SessionName: String;
virtualDesktopName: string;
AllDatabases: TWideStringList;
Databases: TWideStringList;
btnAddTab: TPngSpeedButton;
QueryTabs: TObjectList;
// Cached forms
TableToolsDialog: TfrmTableTools;
ViewEditor: TfrmView;
UserManagerForm: TUserManagerForm;
@ -765,50 +764,71 @@ type
TriggerEditor: TfrmTriggerEditor;
OptionsForm: Toptionsform;
SessionManager: TConnForm;
AllDatabases, Databases: TWideStringList;
TemporaryDatabase : String;
dataselected : Boolean;
editing : Boolean;
WindowNumber : Integer;
SessionName : String;
CreateDatabaseForm: TCreateDatabaseForm;
TableEditor: TfrmTableEditor;
InsertFiles: TfrmInsertFiles;
EditVariableForm: TfrmEditVariable;
// Virtual Tree data arrays
VTRowDataListVariables,
VTRowDataListStatus,
VTRowDataListProcesses,
VTRowDataListCommandStats,
VTRowDataListTables: TVTreeDataArray;
// Variables set by preferences dialog
prefRememberFilters: Boolean;
prefLogsqlnum,
prefLogSqlWidth,
prefMaxColWidth,
prefLogsqlnum: Integer;
prefLogSqlWidth: Integer;
prefMaxColWidth: Integer;
prefMaxTotalRows: Integer;
prefCSVSeparator,
prefCSVEncloser,
prefCSVSeparator: String;
prefCSVEncloser: String;
prefCSVTerminator: String;
prefLogToFile,
prefEnableBinaryEditor,
prefEnableDatetimeEditor,
prefEnableEnumEditor,
prefEnableSetEditor,
prefEnableNullBG,
prefLogToFile: Boolean;
prefEnableBinaryEditor: Boolean;
prefEnableDatetimeEditor: Boolean;
prefEnableEnumEditor: Boolean;
prefEnableSetEditor: Boolean;
prefEnableNullBG: Boolean;
prefExportLocaleNumbers: Boolean;
prefNullColorDefault,
prefNullColorDefault: TColor;
prefNullBG: TColor;
CreateDatabaseForm : TCreateDatabaseForm;
TableEditor : TfrmTableEditor;
InsertFiles : TfrmInsertFiles;
// Data grid related stuff
FDataGridSelect: TWideStringList;
FDataGridSort: TOrderColArray;
FDataGridFocusedNodeIndex: Cardinal;
FDataGridFocusedColumnIndex: TColumnIndex;
DataGridCurrentSelect,
DataGridCurrentFullSelect,
DataGridCurrentFrom,
DataGridCurrentFilter,
DataGridCurrentSelect: String;
DataGridCurrentFullSelect: String;
DataGridCurrentFrom: String;
DataGridCurrentFilter: String;
DataGridCurrentSort: String;
btnAddTab : TPngSpeedButton;
QueryTabs : TObjectList;
DataGridDB: String;
DataGridTable: String;
DataGridHasChanges: Boolean;
DataGridResult: TGridResult;
SelectedTableCreateStatement: String;
SelectedTableColumns: TTableColumnList;
SelectedTableKeys: TTableKeyList;
SelectedTableForeignKeys: TForeignKeyList;
FilterPanelManuallyOpened: Boolean;
PrevTableColWidths: TWideStringList;
// Executable file details
AppVerMajor: Integer;
AppVerMinor: Integer;
AppVerRelease: Integer;
AppVerRevision: Integer;
AppVersion: String;
AppDescription: String;
// Common directories
DirnameCommonAppData: String;
DirnameUserAppData: String;
DirnameSnippets: String;
DirnameSessionLogs: String;
property Delimiter: String read FDelimiter write SetDelimiter;
procedure CallSQLHelpWithKeyword( keyword: String );
@ -819,14 +839,11 @@ type
procedure PopupQueryLoadRemoveAbsentFiles( sender: TObject );
procedure SessionConnect(Sender: TObject);
function InitConnection(parHost, parSocketname, parPort, parUser, parPass, parCompress, parSession: String): Boolean;
function ActiveGrid: TVirtualStringTree;
function GridResult(Grid: TBaseVirtualTree): TGridResult; overload;
function GridResult(PageIndex: Integer): TGridResult; overload;
property ActiveDatabase : String read GetActiveDatabase write SetSelectedDatabase;
property SelectedTable : TDBObject read GetSelectedTable;
procedure TestVTreeDataArray( P: PVTreeDataArray );
function GetVTreeDataArray( VT: TBaseVirtualTree ): PVTreeDataArray;
procedure ActivateFileLogging;
@ -864,26 +881,9 @@ end;
var
MainForm: TMainForm;
AppVerMajor, AppVerMinor, AppVerRelease, AppVerRevision: Integer;
AppVersion, AppDescription: String;
DirnameCommonAppData,
DirnameUserAppData,
DirnameSnippets,
DirnameSessionLogs : String;
const
discname = 'not connected';
ICON_MYSELF_CONNECTED = 38;
ICON_MYSELF_DISCONNECTED = -1;
ICON_OTHER_CONNECTED = 36;
ICON_OTHER_DISCONNECTED = -1;
// The InnoDB folks are raging over the lack of count(*) support
// in the storage engine. To avoid count(*), the first of these
// constants decide how many rows the data area should estimate
// in any table. The second value decides how many percent above the
// number of seen (or simulated) rows the scrollbar should project.
SIMULATE_INITIAL_ROWS = 10000;
SIMULATE_MORE_ROWS = 20;
// Customized messages
MSG_UPDATECHECK = WM_USER + 1;
MSG_ABOUT = WM_USER + 2;
@ -1194,8 +1194,6 @@ begin
// Folder for session logfiles
DirnameSessionLogs := DirnameUserAppData + 'Sessionlogs\';
TemporaryDatabase := '';
// SQLFiles-History
FillPopupQueryLoad;
@ -2554,7 +2552,6 @@ var
begin
// Refresh
// Force data tab update when appropriate.
dataselected := false;
tab1 := PageControlMain.ActivePage;
if ActiveControl = DBtree then
RefreshTree(True)
@ -3272,7 +3269,6 @@ begin
if (SelectedTable.Name = '') or (ActiveDatabase = '') then
Exit;
Screen.Cursor := crHourglass;
viewingdata := true;
sl_query := TWideStringList.Create();
// Ensure grid has left editing mode so DataGrid.OnNewText applies its changes
@ -3399,8 +3395,6 @@ begin
end;
debug('mem: browse row initialization complete.');
dataselected := true;
PageControlMainChange(Self);
finally
DataGrid.Header.Columns.EndUpdate;
@ -3418,7 +3412,6 @@ begin
SelectNode(DataGrid, FDataGridFocusedNodeIndex);
if DataGrid.Header.Columns.Count > FDataGridFocusedColumnIndex then
DataGrid.FocusedColumn := FDataGridFocusedColumnIndex;
viewingdata := false;
EnumerateRecentFilters;
Screen.Cursor := crDefault;
end;
@ -3828,7 +3821,6 @@ begin
end;
// Avoid excessive GridHighlightChanged() when flicking controls.
viewingdata := true;
ProgressBarStatus.Hide;
if Assigned(Results) and Results.HasResult then begin
@ -3883,7 +3875,6 @@ begin
end;
// Ensure controls are in a valid state
ValidateControls(Sender);
viewingdata := false;
Screen.Cursor := crDefault;
ShowStatus( STATUS_MSG_READY );
end;
@ -8499,8 +8490,6 @@ var
begin
// Set window caption and taskbar text
Cap := SessionName;
if WindowNumber <> 0 then
Cap := Cap + Format( ' (%d)', [WindowNumber] );
if ActiveDatabase <> '' then
Cap := Cap + ' /' + ActiveDatabase;
if SelectedTable.Name <> '' then

View File

@ -293,7 +293,7 @@ begin
Mainform.ActivateFileLogging
else if Mainform.prefLogToFile then
Mainform.DeactivateFileLogging;
btnOpenLogFolder.Enabled := DirectoryExists(DirnameSessionLogs);
btnOpenLogFolder.Enabled := DirectoryExists(Mainform.DirnameSessionLogs);
Mainform.prefMaxColWidth := updownMaxColWidth.Position;
Mainform.prefMaxTotalRows := maxrows;
Mainform.prefCSVSeparator := editCSVSeparator.Text;
@ -392,7 +392,7 @@ begin
// Log to file
chkLogToFile.Checked := GetRegValue(REGNAME_LOGTOFILE, DEFAULT_LOGTOFILE);
btnOpenLogFolder.Enabled := DirectoryExists(DirnameSessionLogs);
btnOpenLogFolder.Enabled := DirectoryExists(Mainform.DirnameSessionLogs);
// SQL:
Mainform.SetupSynEditors;
@ -475,7 +475,7 @@ end;
}
procedure Toptionsform.btnOpenLogFolderClick(Sender: TObject);
begin
ShellExec( '', DirnameSessionLogs );
ShellExec( '', Mainform.DirnameSessionLogs );
end;
{**

View File

@ -961,7 +961,7 @@ begin
WideFormat('# %-30s%s', ['Database:', DBObj.Database]) + CRLF +
WideFormat('# %-30s%s', ['Server version:', Mainform.Connection.ServerVersionUntouched]) + CRLF +
WideFormat('# %-30s%s', ['Server OS:', Mainform.Connection.GetVar('SHOW VARIABLES LIKE ' + esc('version_compile_os'), 1)]) + CRLF +
WideFormat('# %-30s%s', [APPNAME + ' version:', AppVersion]) + CRLF +
WideFormat('# %-30s%s', [APPNAME + ' version:', Mainform.AppVersion]) + CRLF +
WideFormat('# %-30s%s', ['Date/time:', DateTimeToStr(Now)]) + CRLF +
'# --------------------------------------------------------' + CRLF + CRLF +
'/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' + CRLF +

View File

@ -104,8 +104,8 @@ begin
// Prepare download
CheckfileDownload := TDownLoadURL2.Create(Self);
CheckfileDownload.SetUserAgent(APPNAME + ' ' + AppVersion + ' update checker tool');
CheckfileDownload.URL := APPDOMAIN + 'updatecheck.php?r='+IntToStr(AppVerRevision);
CheckfileDownload.SetUserAgent(APPNAME + ' ' + Mainform.AppVersion + ' update checker tool');
CheckfileDownload.URL := APPDOMAIN + 'updatecheck.php?r='+IntToStr(Mainform.AppVerRevision);
CheckfileDownload.Filename := GetTempDir + APPNAME + '_updatecheck.ini';
// Download the check file
@ -117,9 +117,9 @@ begin
ReadCheckFile;
// Developer versions probably have "unknown" (0) as revision,
// which makes it impossible to compare the revisions.
if AppVerRevision = 0 then
if Mainform.AppVerRevision = 0 then
Status('Error: Cannot determine current revision. Using a developer version?')
else if AppVerRevision = BuildRevision then
else if Mainform.AppVerRevision = BuildRevision then
Status('Your '+APPNAME+' is up-to-date (no update available).')
else if groupRelease.Enabled or btnBuild.Enabled then
Status('Updates available.');
@ -166,14 +166,14 @@ begin
ReleaseVersion := Ini.ReadString(INISECT_RELEASE, 'Version', 'unknown');
ReleaseRevision := Ini.ReadInteger(INISECT_RELEASE, 'Revision', 0);
ReleaseURL := Ini.ReadString(INISECT_RELEASE, 'URL', '');
memoRelease.Lines.Add( 'Version ' + ReleaseVersion + ' (yours: '+AppVersion+')' );
memoRelease.Lines.Add( 'Version ' + ReleaseVersion + ' (yours: '+Mainform.AppVersion+')' );
memoRelease.Lines.Add( 'Released: ' + Ini.ReadString(INISECT_RELEASE, 'Date', '') );
Note := Ini.ReadString(INISECT_RELEASE, 'Note', '');
if Note <> '' then
memoRelease.Lines.Add( 'Note: ' + Note );
btnRelease.Caption := 'Download version ' + ReleaseVersion;
// Enable the download button if the current version is outdated
groupRelease.Enabled := ReleaseRevision > AppVerRevision;
groupRelease.Enabled := ReleaseRevision > Mainform.AppVerRevision;
btnRelease.Enabled := groupRelease.Enabled;
memoRelease.Enabled := groupRelease.Enabled;
if not memoRelease.Enabled then
@ -187,7 +187,7 @@ begin
BuildRevision := Ini.ReadInteger(INISECT_BUILD, 'Revision', 0);
BuildURL := Ini.ReadString(INISECT_BUILD, 'URL', '');
BuildSize := Ini.ReadInteger(INISECT_BUILD, 'Size', 0);
memoBuild.Lines.Add( 'Revision ' + IntToStr(BuildRevision) + ' (yours: '+IntToStr(AppVerRevision)+')' );
memoBuild.Lines.Add( 'Revision ' + IntToStr(BuildRevision) + ' (yours: '+IntToStr(Mainform.AppVerRevision)+')' );
FileAge(ParamStr(0), Compiled);
memoBuild.Lines.Add( 'Compiled: ' + Ini.ReadString(INISECT_BUILD, 'Date', '') + ' (yours: '+DateToStr(Compiled)+')' );
Note := Ini.ReadString(INISECT_BUILD, 'Note', '');
@ -197,7 +197,7 @@ begin
// A new release should have priority over a new nightly build.
// So the user should not be able to download a newer build here
// before having installed the new release.
btnBuild.Enabled := (AppVerRevision = 0) or ((BuildRevision > AppVerRevision) and (not btnRelease.Enabled));
btnBuild.Enabled := (Mainform.AppVerRevision = 0) or ((BuildRevision > Mainform.AppVerRevision) and (not btnRelease.Enabled));
end;
end;