Skip to content
Permalink
Browse files

Prefer string helpers .ToLowerInvariant and .ToUpperInvariant over cu…

  • Loading branch information
ansgarbecker committed Jan 30, 2020
1 parent 5ee148b commit 80542d195973752fd5501127163b0bddc1230cb2
Showing with 129 additions and 130 deletions.
  1. +13 −14 source/dbconnection.pas
  2. +116 −116 source/theme_preview.pas
@@ -3161,7 +3161,7 @@ function TMySQLConnection.GetCreateCode(Obj: TDBObject): String;
lntEvent: ColIdx := 3;
else raise EDbError.CreateFmt(_('Unhandled list node type in %s.%s'), [ClassName, 'GetCreateCode']);
end;
Result := GetVar('SHOW CREATE '+Obj.ObjType.ToUpper+' '+QuoteIdent(Obj.Database)+'.'+QuoteIdent(Obj.Name), ColIdx);
Result := GetVar('SHOW CREATE '+Obj.ObjType.ToUpperInvariant+' '+QuoteIdent(Obj.Database)+'.'+QuoteIdent(Obj.Name), ColIdx);
end;


@@ -4594,14 +4594,14 @@ function TDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
Col.Expression := ColQuery.Col('GENERATION_EXPRESSION', True);
// PG has no extra:
ExtraText := ColQuery.Col('EXTRA', True);
Col.Virtuality := RegExprGetMatch('^(\w+)\s+generated$', ExtraText.ToLower, 1);
Col.AllowNull := ColQuery.Col('IS_NULLABLE').ToLower = 'yes';
Col.Virtuality := RegExprGetMatch('^(\w+)\s+generated$', ExtraText.ToLowerInvariant, 1);
Col.AllowNull := ColQuery.Col('IS_NULLABLE').ToLowerInvariant = 'yes';

DefText := ColQuery.Col('COLUMN_DEFAULT');
Col.OnUpdateType := cdtNothing;
if DefText.ToLower = 'null' then begin
if DefText.ToLowerInvariant = 'null' then begin
Col.DefaultType := cdtNull;
end else if ExecRegExpr('^auto_increment$', ExtraText.ToLower) then begin
end else if ExecRegExpr('^auto_increment$', ExtraText.ToLowerInvariant) then begin
Col.DefaultType := cdtAutoInc;
Col.DefaultText := 'AUTO_INCREMENT';
end else if ColQuery.IsNull('COLUMN_DEFAULT') then begin
@@ -4652,14 +4652,14 @@ function TMySQLConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
Col.OldName := Col.Name;
Col.ParseDatatype(ColQuery.Col('Type'));
Col.Collation := ColQuery.Col('Collation');
if Col.Collation.ToLower = 'null' then
if Col.Collation.ToLowerInvariant = 'null' then
Col.Collation := '';
Col.AllowNull := ColQuery.Col('Null').ToLower = 'yes';
Col.AllowNull := ColQuery.Col('Null').ToLowerInvariant = 'yes';

DefText := ColQuery.Col('Default');
ExtraText := ColQuery.Col('Extra');
Col.OnUpdateType := cdtNothing;
if ExecRegExpr('^auto_increment$', ExtraText.ToLower) then begin
if ExecRegExpr('^auto_increment$', ExtraText.ToLowerInvariant) then begin
Col.DefaultType := cdtAutoInc;
Col.DefaultText := 'AUTO_INCREMENT';
end else if ColQuery.IsNull('Default') then begin
@@ -4799,7 +4799,7 @@ function TDBConnection.GetTableKeys(Table: TDBObject): TTableKeyList;
Result.Add(NewKey);
NewKey.Name := KeyQuery.Col('CONSTRAINT_NAME');
NewKey.OldName := NewKey.Name;
if KeyQuery.Col('CONSTRAINT_TYPE').ToLower.StartsWith('primary') then
if KeyQuery.Col('CONSTRAINT_TYPE').ToLowerInvariant.StartsWith('primary') then
NewKey.IndexType := 'PRIMARY'
else
NewKey.IndexType := KeyQuery.Col('CONSTRAINT_TYPE');
@@ -4828,7 +4828,7 @@ function TMySQLConnection.GetTableKeys(Table: TDBObject): TTableKeyList;
Result.Add(NewKey);
NewKey.Name := KeyQuery.Col('Key_name');
NewKey.OldName := NewKey.Name;
if NewKey.Name.ToLower = 'primary' then
if NewKey.Name.ToLowerInvariant = 'primary' then
NewKey.IndexType := 'PRIMARY'
else if KeyQuery.Col('Non_unique') = '0' then
NewKey.IndexType := 'UNIQUE'
@@ -4838,7 +4838,6 @@ function TMySQLConnection.GetTableKeys(Table: TDBObject): TTableKeyList;
NewKey.OldIndexType := NewKey.IndexType;
NewKey.Algorithm := KeyQuery.Col('Index_type');
NewKey.Comment := KeyQuery.Col('Index_comment', True);
Log(lcDebug, 'NewKey.Name="'+NewKey.Name+'", NewKey.Name.ToLower="'+NewKey.Name.ToLower+'", NewKey.IndexType="'+NewKey.IndexType+'"');
end;
NewKey.Columns.Add(KeyQuery.Col('Column_name'));
NewKey.SubParts.Add(KeyQuery.Col('Sub_part'));
@@ -4905,7 +4904,7 @@ function TPGConnection.GetTableKeys(Table: TDBObject): TTableKeyList;
NewKey.Name := KeyQuery.Col('CONSTRAINT_NAME');
NewKey.OldName := NewKey.Name;
NewKey.IndexType := KeyQuery.Col('CONSTRAINT_TYPE');
if NewKey.IndexType.ToLower.EndsWith(' key') then
if NewKey.IndexType.ToLowerInvariant.EndsWith(' key') then
Delete(NewKey.IndexType, Length(NewKey.IndexType)-4, 4);
NewKey.OldIndexType := NewKey.IndexType;
end;
@@ -8786,8 +8785,8 @@ procedure TTableColumn.ParseDatatype(Source: String);
InLiteral := not InLiteral;
end;
LengthSet := Copy(Source, ParenthLeft+1, i-2);
Unsigned := ExecRegExpr('\sunsigned[\s\w]*$', Source.ToLower);
ZeroFill := ExecRegExpr('\szerofill[\s\w]*$', Source.ToLower);
Unsigned := ExecRegExpr('\sunsigned[\s\w]*$', Source.ToLowerInvariant);
ZeroFill := ExecRegExpr('\szerofill[\s\w]*$', Source.ToLowerInvariant);
end else begin
LengthSet := '';
Unsigned := False;
@@ -1,116 +1,116 @@
unit theme_preview;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.StdCtrls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, apphelpers,
Vcl.ComCtrls, Vcl.GraphUtil, Vcl.Imaging.pngimage, extra_controls;

type
TfrmThemePreview = class(TExtForm)
StatusBarMain: TStatusBar;
ScrollBoxImage: TScrollBox;
imagePreview: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure ScrollBoxImageMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
private
{ Private declarations }
FToggleCheckbox: TCheckBox;
FLastStatusUpdate: Cardinal;
FTempFile: String;
procedure DownloadProgress(Sender: TObject);
public
{ Public declarations }
procedure LoadTheme(ThemeName: String);
end;


implementation

{$R *.dfm}



procedure TfrmThemePreview.FormCreate(Sender: TObject);
begin
FToggleCheckbox := TCheckBox(Owner);
end;


procedure TfrmThemePreview.FormShow(Sender: TObject);
begin
Width := AppSettings.ReadInt(asThemePreviewWidth);
Height := AppSettings.ReadInt(asThemePreviewHeight);
Top := AppSettings.ReadInt(asThemePreviewTop);
Left := AppSettings.ReadInt(asThemePreviewLeft);
ToggleCheckBoxWithoutClick(FToggleCheckbox, True);
end;

procedure TfrmThemePreview.FormClose(Sender: TObject; var Action: TCloseAction);
begin

AppSettings.WriteInt(asThemePreviewWidth, Width);
AppSettings.WriteInt(asThemePreviewHeight, Height);
AppSettings.WriteInt(asThemePreviewTop, Top);
AppSettings.WriteInt(asThemePreviewLeft, Left);
ToggleCheckBoxWithoutClick(FToggleCheckbox, False);
Action := caFree;
end;


procedure TfrmThemePreview.LoadTheme(ThemeName: String);
var
Download: THttpDownload;
ThemeImage: String;
begin
Download := THttpDownload.Create(Self);
ThemeImage := ThemeName;
ThemeImage := ThemeName.Replace(' ', '-').ToLower;
Download.URL := Format('%simages/themes/%s.png', [APPDOMAIN, ThemeImage]);
StatusBarMain.SimpleText := 'Loading preview: ' + Download.URL;
FTempFile := Format('%s%s-themepreview-%s.png', [GetTempDir, APPNAME, ThemeImage]);
Download.OnProgress := DownloadProgress;
try
Download.SendRequest(FTempFile);
imagePreview.Picture.LoadFromFile(FTempFile);
StatusBarMain.SimpleText := Format('Theme name: %s', [ThemeName]);
except
on E:Exception do begin
StatusBarMain.SimpleText := E.Message;
end;
end;
end;


procedure TfrmThemePreview.ScrollBoxImageMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
begin
// Scrolling via mouse wheel
// Do not use .ScrollBy(), which makes the scroll bar longer
if KeyPressed(VK_SHIFT) then begin
ScrollBoxImage.HorzScrollBar.Position := ScrollBoxImage.HorzScrollBar.Position - WheelDelta;
end else begin
ScrollBoxImage.VertScrollBar.Position := ScrollBoxImage.VertScrollBar.Position - WheelDelta;
end;
Handled := True;
end;

procedure TfrmThemePreview.DownloadProgress(Sender: TObject);
var
Download: THttpDownload;
begin
if FLastStatusUpdate > GetTickCount-200 then
Exit;
Download := Sender as THttpDownload;
StatusBarMain.SimpleText := f_('Downloading: %s / %s', [FormatByteNumber(Download.BytesRead), FormatByteNumber(Download.ContentLength)]) + ' ...';
FLastStatusUpdate := GetTickCount;
end;



end.
unit theme_preview;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.StdCtrls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, apphelpers,
Vcl.ComCtrls, Vcl.GraphUtil, Vcl.Imaging.pngimage, extra_controls;

type
TfrmThemePreview = class(TExtForm)
StatusBarMain: TStatusBar;
ScrollBoxImage: TScrollBox;
imagePreview: TImage;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure ScrollBoxImageMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
private
{ Private declarations }
FToggleCheckbox: TCheckBox;
FLastStatusUpdate: Cardinal;
FTempFile: String;
procedure DownloadProgress(Sender: TObject);
public
{ Public declarations }
procedure LoadTheme(ThemeName: String);
end;


implementation

{$R *.dfm}



procedure TfrmThemePreview.FormCreate(Sender: TObject);
begin
FToggleCheckbox := TCheckBox(Owner);
end;


procedure TfrmThemePreview.FormShow(Sender: TObject);
begin
Width := AppSettings.ReadInt(asThemePreviewWidth);
Height := AppSettings.ReadInt(asThemePreviewHeight);
Top := AppSettings.ReadInt(asThemePreviewTop);
Left := AppSettings.ReadInt(asThemePreviewLeft);
ToggleCheckBoxWithoutClick(FToggleCheckbox, True);
end;

procedure TfrmThemePreview.FormClose(Sender: TObject; var Action: TCloseAction);
begin

AppSettings.WriteInt(asThemePreviewWidth, Width);
AppSettings.WriteInt(asThemePreviewHeight, Height);
AppSettings.WriteInt(asThemePreviewTop, Top);
AppSettings.WriteInt(asThemePreviewLeft, Left);
ToggleCheckBoxWithoutClick(FToggleCheckbox, False);
Action := caFree;
end;


procedure TfrmThemePreview.LoadTheme(ThemeName: String);
var
Download: THttpDownload;
ThemeImage: String;
begin
Download := THttpDownload.Create(Self);
ThemeImage := ThemeName;
ThemeImage := ThemeName.Replace(' ', '-').ToLowerInvariant;
Download.URL := Format('%simages/themes/%s.png', [APPDOMAIN, ThemeImage]);
StatusBarMain.SimpleText := 'Loading preview: ' + Download.URL;
FTempFile := Format('%s%s-themepreview-%s.png', [GetTempDir, APPNAME, ThemeImage]);
Download.OnProgress := DownloadProgress;
try
Download.SendRequest(FTempFile);
imagePreview.Picture.LoadFromFile(FTempFile);
StatusBarMain.SimpleText := Format('Theme name: %s', [ThemeName]);
except
on E:Exception do begin
StatusBarMain.SimpleText := E.Message;
end;
end;
end;


procedure TfrmThemePreview.ScrollBoxImageMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
begin
// Scrolling via mouse wheel
// Do not use .ScrollBy(), which makes the scroll bar longer
if KeyPressed(VK_SHIFT) then begin
ScrollBoxImage.HorzScrollBar.Position := ScrollBoxImage.HorzScrollBar.Position - WheelDelta;
end else begin
ScrollBoxImage.VertScrollBar.Position := ScrollBoxImage.VertScrollBar.Position - WheelDelta;
end;
Handled := True;
end;

procedure TfrmThemePreview.DownloadProgress(Sender: TObject);
var
Download: THttpDownload;
begin
if FLastStatusUpdate > GetTickCount-200 then
Exit;
Download := Sender as THttpDownload;
StatusBarMain.SimpleText := f_('Downloading: %s / %s', [FormatByteNumber(Download.BytesRead), FormatByteNumber(Download.ContentLength)]) + ' ...';
FLastStatusUpdate := GetTickCount;
end;



end.

0 comments on commit 80542d1

Please sign in to comment.
You can’t perform that action at this time.