Skip to content

Commit f1ac6dc

Browse files
committed
fix: fix various compiler hints and warnings
Adds a {%H-} prefix to a few where the compiler is complaining wrongly. Note: {%H-} affects just the IDE, not the command line.
1 parent c054884 commit f1ac6dc

File tree

7 files changed

+39
-34
lines changed

7 files changed

+39
-34
lines changed

source/apphelpers.pas

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ TAppSettings = class(TObject)
404404
function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; KeepAskingSetting: TAppSettingIndex=asUnused; FooterText: String=''): Integer; overload;
405405
function ErrorDialog(Msg: string): Integer; overload;
406406
function ErrorDialog(const Title, Msg: string): Integer; overload;
407-
function GetLocaleString(const ResourceId: Integer): UnicodeString;
407+
function GetLocaleString(const ResourceId: Integer): String;
408408
function GetHTMLCharsetByEncoding(Encoding: TEncoding): String;
409409
procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectionParameters; var FileNames: TStringList; var RunFrom: String);
410410
procedure InitMoFile(LangCode: String);
@@ -1403,7 +1403,7 @@ function ReadTextfileChunk(Stream: TFileStream; Encoding: TEncoding; ChunkSize:
14031403

14041404
SetLength(Bytes, ChunkSize);
14051405
Stream.ReadBuffer(Bytes[0], Length(Bytes));
1406-
Result := Encoding.GetString(Bytes);
1406+
Result := Encoding.GetAnsiString(Bytes);
14071407
end;
14081408

14091409

@@ -2444,17 +2444,20 @@ function ErrorDialog(const Title, Msg: string): Integer;
24442444
end;
24452445

24462446

2447-
function GetLocaleString(const ResourceId: Integer): UnicodeString;
2447+
function GetLocaleString(const ResourceId: Integer): String;
24482448
var
24492449
Buffer: array[0..255] of WideChar;
2450+
WS: UnicodeString;
24502451
BufferLen: Integer;
24512452
begin
24522453
Result := '';
24532454
{$IFDEF WINDOWS}
24542455
if LibHandleUser32 <> 0 then begin
2455-
BufferLen := LoadStringW(LibHandleUser32, ResourceId, @Buffer[0], Length(Buffer));
2456-
if BufferLen > 0 then
2457-
Result := UnicodeString(Buffer);
2456+
BufferLen := LoadStringW(LibHandleUser32, ResourceId, {%H-}Buffer, Length(Buffer));
2457+
if BufferLen > 0 then begin
2458+
SetString(WS, PWideChar(@Buffer[0]), BufferLen);
2459+
Result := UTF16ToUTF8(WS);
2460+
end;
24582461
end;
24592462
{$ENDIF}
24602463
end;

source/crashdialog.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ implementation
3535
procedure TfrmCrashDialog.btnCopyClick(Sender: TObject);
3636
begin
3737
memoDetails.CopyToClipboard;
38-
btnCopy.Caption := btnCopy.Caption + ' ' + #10003;
38+
btnCopy.Caption := btnCopy.Caption + ' ' + '';
3939
// enable timer which resets the button caption?
4040
end;
4141

source/dbconnection.pas

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,7 @@ function TDBConnection.GetDatatypeByName(var DataType: String; DeleteFromSource:
22172217
Types, tmp: String;
22182218
TypesSorted: TStringList;
22192219
begin
2220+
Result := Default(TDBDatatype);
22202221
rx := TRegExpr.Create;
22212222
rx.ModifierI := True;
22222223
MatchLen := 0;
@@ -2274,6 +2275,7 @@ function TDBConnection.GetDatatypeByNativeType(NativeType: Integer; Identifier:
22742275
TypeFound: Boolean;
22752276
TypeOid: String;
22762277
begin
2278+
Result := Default(TDBDatatype);
22772279
rx := TRegExpr.Create;
22782280
TypeFound := False;
22792281
for i:=0 to High(Datatypes) do begin
@@ -5830,7 +5832,9 @@ function TDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
58305832
dt := 'UDT_NAME'
58315833
else
58325834
dt := 'DATA_TYPE';
5833-
end;
5835+
end
5836+
else
5837+
dt := '?';
58345838
Col.ParseDatatype(ColQuery.Col(dt));
58355839
// PG/MSSQL don't include length in data type
58365840
if Col.LengthSet.IsEmpty and Col.DataType.HasLength then begin
@@ -7893,6 +7897,7 @@ procedure TDBConnection.ParseRoutineStructure(Obj: TDBObject; Parameters: TRouti
78937897
ParenthesesCount := 0;
78947898
Params := '';
78957899
InLiteral := False;
7900+
i := 0;
78967901
for i:=1 to Length(CreateCode) do begin
78977902
if (CreateCode[i] = ')') and (not InLiteral) then begin
78987903
Dec(ParenthesesCount);
@@ -9049,9 +9054,9 @@ function TMySQLQuery.Col(Column: Integer; IgnoreErrors: Boolean=False): String;
90499054
if Datatype(Column).Index = dbdtBit then begin
90509055
Field := FConnection.Lib.mysql_fetch_field_direct(FCurrentResults, column);
90519056
// FConnection.Log(lcInfo, Field.name+': def: '+field.def+' length: '+inttostr(field.length)+' max_length: '+inttostr(field.max_length)+' decimals: '+inttostr(field.decimals));
9057+
BitString := '';
90529058
for c in Result do begin
90539059
ByteVal := Byte(c);
9054-
BitString := '';
90559060
for NumBit:=0 to 7 do begin
90569061
if (ByteVal shr NumBit and $1) = $1 then
90579062
BitString := BitString + '1'
@@ -9174,10 +9179,11 @@ function TDBQuery.ColumnLengths(Column: Integer): Int64;
91749179

91759180
function TDBQuery.HexValue(Column: Integer; IgnoreErrors: Boolean=False): String;
91769181
var
9177-
baData: TBytes;
9182+
baData: TBytes;
91789183
begin
91799184
// Return a binary column value as hex AnsiString
91809185
if FConnection.Parameters.IsAnyMysql then begin
9186+
baData := [];
91819187
GetColBinData(Column, baData);
91829188
Result := FConnection.EscapeBin(baData);
91839189
end else

source/loaddata.pas

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
546546

547547
procedure AddRow;
548548
var
549-
SA: AnsiString;
550-
ChunkSize: Int64;
549+
S: String;
551550
i: Integer;
552551
begin
553552
if SQL = '' then
@@ -566,13 +565,15 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
566565
if (OutStream.Size < PacketSize) and (P < ContentLen) and (RowCountInChunk < FConnection.MaxRowsPerInsert) then begin
567566
SQL := SQL + ', (';
568567
end else begin
568+
569569
OutStream.Position := 0;
570-
ChunkSize := OutStream.Size;
571-
SA := '';
572-
SetLength(SA, ChunkSize div SizeOf(AnsiChar));
573-
OutStream.Read(PAnsiChar(SA)^, ChunkSize);
570+
S := '';
571+
SetLength(S, OutStream.Size);
572+
if OutStream.Size > 0 then
573+
OutStream.ReadBuffer(S[1], OutStream.Size);
574574
OutStream.Size := 0;
575-
FConnection.Query(UTF8ToString(SA), False, lcScript);
575+
576+
FConnection.Query(S, False, lcScript);
576577
Inc(FRowCount, Max(FConnection.RowsAffected, 0));
577578
FConnection.ShowWarnings;
578579
SQL := '';

source/main.pas

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface
1414
Types, LCLType, EditBtn, FileUtil, LMessages, jsonconf, DelphiCompat,
1515
LazStringUtils, dbconnection, dbstructures, dbstructures.mysql, generic_types,
1616
apphelpers, extra_controls, createdatabase, SynEditMarkupBracket,
17-
searchreplace, ImgList, IniFiles, LazFileUtils, tabletools,
17+
searchreplace, ImgList, IniFiles, LazFileUtils, LazUTF8, tabletools,
1818
lazaruscompat, extfiledialog;
1919

2020

@@ -2781,10 +2781,7 @@ procedure TMainForm.actClearEditorExecute(Sender: TObject);
27812781
m := SynMemoFilter;
27822782
editFilterSearch.Clear;
27832783
end;
2784-
m.SelectAll;
2785-
m.SelText := '';
2786-
m.SelStart := 0;
2787-
m.SelEnd := 0;
2784+
m.ClearAll;
27882785
if Sender = actClearQueryEditor then begin
27892786
QueryTabs.ActiveTab.MemoFilename := '';
27902787
QueryTabs.ActiveTab.Memo.Modified := False;
@@ -5272,7 +5269,7 @@ procedure TMainForm.actDataInsertExecute(Sender: TObject);
52725269
if (Sender = actDataDuplicateRowWithoutKeys) or (Sender = actDataDuplicateRowWithKeys) then
52735270
DupeNode := Grid.FocusedNode;
52745271
RowNum := Results.InsertRow;
5275-
NewNode := Grid.InsertNode(Grid.FocusedNode, amInsertAfter, PInt64(RowNum));
5272+
NewNode := Grid.InsertNode(Grid.FocusedNode, amInsertAfter, @RowNum);
52765273
SelectNode(Grid, NewNode);
52775274
if Assigned(DupeNode) then begin
52785275
// Copy values from source row, ensure we have whole cell data
@@ -5629,7 +5626,8 @@ procedure TMainForm.AnyGridAdvancedHeaderDraw(Sender: TVTHeader;
56295626
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
56305627
var
56315628
PaintArea, TextArea, IconArea, SortArea: TRect;
5632-
SortText, ColCaption, ColIndex: WideString;
5629+
SortText, ColCaptionW, ColIndex: WideString;
5630+
ColCaption: String;
56335631
TextSpace, ColSortIndex, NumCharTop: Integer;
56345632
ColSortDirection: laz.VirtualTrees.TSortDirection;
56355633
TextSize: TSize;
@@ -5670,13 +5668,13 @@ procedure TMainForm.AnyGridAdvancedHeaderDraw(Sender: TVTHeader;
56705668
PaintArea := PaintInfo.PaintRectangle;
56715669
PaintArea.Inflate(-PaintInfo.Column.Margin, 0);
56725670
DeviceContext := PaintInfo.TargetCanvas.Handle;
5671+
DrawFormat := DT_TOP or DT_NOPREFIX or DT_LEFT;
56735672

56745673
// Draw column name. Code taken from TVirtualTreeColumns.DrawButtonText and modified for our needs
56755674
if hpeText in Elements then begin
56765675

56775676
TextArea := PaintArea;
56785677
SetBkMode(DeviceContext, TRANSPARENT);
5679-
DrawFormat := DT_TOP or DT_NOPREFIX or DT_LEFT;
56805678

56815679
if AppSettings.ReadBool(asShowRowId) and (PaintInfo.Column.Index > 0) then begin
56825680
// Paint gray column number left to its caption
@@ -5711,7 +5709,8 @@ procedure TMainForm.AnyGridAdvancedHeaderDraw(Sender: TVTHeader;
57115709
end;
57125710

57135711
SetTextColor(DeviceContext, ColorToRGB(clWindowText));
5714-
DrawTextW(DeviceContext, PWideChar(ColCaption), Length(ColCaption), TextArea, DrawFormat);
5712+
ColCaptionW := UTF8ToUTF16(ColCaption);
5713+
DrawTextW(DeviceContext, PWideChar(ColCaptionW), Length(ColCaption), TextArea, DrawFormat);
57155714
end;
57165715

57175716
// Draw image, if any

source/tabletools.pas

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,9 +1723,6 @@ procedure TfrmTableTools.SetToolMode(Value: TToolMode);
17231723

17241724
// Pass output to file or query, and append semicolon if needed
17251725
procedure TfrmTableTools.Output(SQL: String; IsEndOfQuery, ForFile, ForDir, ForDb, ForServer: Boolean);
1726-
var
1727-
SA: AnsiString;
1728-
ChunkSize: Integer;
17291726
begin
17301727
if (ToFile and ForFile) or (ToDir and ForDir) or (ToClipboard and ForFile) then begin
17311728
if IsEndOfQuery then
@@ -1738,12 +1735,11 @@ procedure TfrmTableTools.Output(SQL: String; IsEndOfQuery, ForFile, ForDir, ForD
17381735
StreamWrite(ExportStream, SQL);
17391736
if IsEndOfQuery then begin
17401737
ExportStream.Position := 0;
1741-
ChunkSize := ExportStream.Size;
1742-
SetLength(SA, ChunkSize div SizeOf(AnsiChar));
1743-
ExportStream.Read(PAnsiChar(SA)^, ChunkSize);
1738+
SetLength(SQL, ExportStream.Size);
1739+
if ExportStream.Size > 0 then
1740+
ExportStream.ReadBuffer(SQL[1], ExportStream.Size);
17441741
ExportStream.Size := 0;
17451742
ExportStreamStartOfQueryPos := 0;
1746-
SQL := UTF8ToString(SA);
17471743
if ToDB then MainForm.ActiveConnection.Query(SQL, False, lcScript)
17481744
else if ToServer then FTargetConnection.Query(SQL, False, lcScript);
17491745
SQL := '';

source/usermanager.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ procedure TUserManagerForm.FormShow(Sender: TObject);
415415
U.Problem := upNone;
416416
if Length(U.Password) = 0 then
417417
U.Problem := upEmptyPassword;
418-
if PasswordLengthMatters and (not (Length(U.Password) in [0, 16, 41])) then
418+
if PasswordLengthMatters and (not (Length(U.Password) {%H-}in [0, 16, 41])) then
419419
U.Problem := upInvalidPasswordLen
420420
else if SkipNameResolve and U.HostRequiresNameResolve then
421421
U.Problem := upSkipNameResolve;

0 commit comments

Comments
 (0)