Merge branch 'cocoa/control/combobox' into 'main'

FIX #39965: COCOA: the issue of Items in ComboBox released too early, fixed to release in dealloc

See merge request freepascal.org/lazarus/lazarus!117
This commit is contained in:
Maxim Ganetsky 2023-05-03 14:04:03 +00:00
commit c19c4b20b9
2 changed files with 11 additions and 0 deletions

View File

@ -1451,6 +1451,7 @@ end;
procedure TCocoaComboBox.dealloc;
begin
FreeAndNil( list );
if Assigned(resultNS) then resultNS.release;
inherited dealloc;
end;

View File

@ -93,6 +93,7 @@ type
class procedure SetDropDownCount(const ACustomComboBox: TCustomComboBox; NewCount: Integer); override;
class function GetItems(const ACustomComboBox: TCustomComboBox): TStrings; override;
class procedure FreeItems(var AItems: TStrings); override;
{class procedure Sort(const ACustomComboBox: TCustomComboBox; AList: TStrings; IsSorted: boolean); override;}
class function GetItemHeight(const ACustomComboBox: TCustomComboBox): Integer; override;
@ -1974,6 +1975,15 @@ begin
Result:=TCocoaComboBox(ACustomComboBox.Handle).list;
end;
class procedure TCocoaWSCustomComboBox.FreeItems(var AItems: TStrings);
begin
// in Cocoa, TCocoaComboBox.list should be released in TCocoaComboBox.dealloc(),
// to avoid invalid TCocoaComboBox.list in TCocoaComboBox.comboBox_indexOfItemWithStringValue().
// which will be called even in TCocoaWSWinControl.DestoryWnd(),
// when TCocoaComboBox hasMarkedText (in IME state).
// after all, it is more appropriate to release with other resources in dealloc().
end;
class function TCocoaWSCustomComboBox.GetItemHeight(const ACustomComboBox:
TCustomComboBox):Integer;
begin