From 21f35c1381a1641a72546d583818a070f8d16c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDeljan=20Rikalo?= Date: Wed, 28 Jun 2023 10:17:16 +0200 Subject: [PATCH] Qt,Qt5,Qt6: fixed error with sorted TQtComboStrings. issue #40353 (cherry picked from commit dcf14bec5a34edfdd6d227852837496bef837dc0) --- lcl/interfaces/qt/qtprivate.pp | 16 +++++++++------- lcl/interfaces/qt5/qtprivate.pp | 16 +++++++++------- lcl/interfaces/qt6/qtprivate.pp | 16 +++++++++------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lcl/interfaces/qt/qtprivate.pp b/lcl/interfaces/qt/qtprivate.pp index 10c92cd85b..1332bd85ad 100644 --- a/lcl/interfaces/qt/qtprivate.pp +++ b/lcl/interfaces/qt/qtprivate.pp @@ -566,15 +566,17 @@ begin end; function TQtComboStrings.Add(const S: String): Integer; +var + I: Integer; begin - if FSorted then + Result := inherited Add(S); + if FSorted and Assigned(FWinControl) and (FWinControl.HandleAllocated) then begin - Find(S, Result); - FChanging := True; - Insert(Result, S); - FChanging := False; - end else - Result := inherited Add(S); + FOwner.BeginUpdate; + for I := 0 to Count - 1 do + FOwner.setItemText(I, Strings[I]); + FOwner.EndUpdate; + end; end; procedure TQtComboStrings.Assign(Source: TPersistent); diff --git a/lcl/interfaces/qt5/qtprivate.pp b/lcl/interfaces/qt5/qtprivate.pp index 0c85e788ac..141d878037 100644 --- a/lcl/interfaces/qt5/qtprivate.pp +++ b/lcl/interfaces/qt5/qtprivate.pp @@ -570,15 +570,17 @@ begin end; function TQtComboStrings.Add(const S: String): Integer; +var + I: Integer; begin - if FSorted then + Result := inherited Add(S); + if FSorted and Assigned(FWinControl) and (FWinControl.HandleAllocated) then begin - Find(S, Result); - FChanging := True; - Insert(Result, S); - FChanging := False; - end else - Result := inherited Add(S); + FOwner.BeginUpdate; + for I := 0 to Count - 1 do + FOwner.setItemText(I, Strings[I]); + FOwner.EndUpdate; + end; end; procedure TQtComboStrings.Assign(Source: TPersistent); diff --git a/lcl/interfaces/qt6/qtprivate.pp b/lcl/interfaces/qt6/qtprivate.pp index 52f08ec2db..c35263c664 100644 --- a/lcl/interfaces/qt6/qtprivate.pp +++ b/lcl/interfaces/qt6/qtprivate.pp @@ -570,15 +570,17 @@ begin end; function TQtComboStrings.Add(const S: String): Integer; +var + I: Integer; begin - if FSorted then + Result := inherited Add(S); + if FSorted and Assigned(FWinControl) and (FWinControl.HandleAllocated) then begin - Find(S, Result); - FChanging := True; - Insert(Result, S); - FChanging := False; - end else - Result := inherited Add(S); + FOwner.BeginUpdate; + for I := 0 to Count - 1 do + FOwner.setItemText(I, Strings[I]); + FOwner.EndUpdate; + end; end; procedure TQtComboStrings.Assign(Source: TPersistent);