Cocoa: fix TComboBoxEx.ItemIndex always return 0

This commit is contained in:
rich2014 2023-09-03 22:33:46 +08:00
parent 22df40bcce
commit fa35acd164
2 changed files with 9 additions and 1 deletions

View File

@ -323,6 +323,7 @@ type
isOwnerDrawn: Boolean;
isOwnerMeasure: Boolean;
isComboBoxEx: Boolean;
function acceptsFirstResponder: LCLObjCBoolean; override;
procedure dealloc; override;
function lclGetCallback: ICommonCallback; override;
@ -491,7 +492,13 @@ begin
mn := FOwner.itemAtIndex(Index);
if not Assigned(mn) then Exit;
astr := NSStringUtf8(S);
// for TComboBoxEx, the parameter S passed in is always emtpy,
// and NSPopUpButton always automatically sets the itemIndex according to
// the title, so a unique title needs to be set.
if not FOwner.isComboBoxEx then
astr := NSStringUtf8(S)
else
astr := NSStringUtf8(Index.ToString);
mn.setTitle(astr);
astr.release;

View File

@ -1880,6 +1880,7 @@ begin
begin
rocmb := NSView(TCocoaReadOnlyComboBox.alloc).lclInitWithCreateParams(AParams);
if not Assigned(rocmb) then Exit;
rocmb.isComboBoxEx:= not (AWinControl is TComboBox);
rocmb.list:=TCocoaReadOnlyComboBoxList.Create(rocmb);
rocmb.setTarget(rocmb);
rocmb.setAction(objcselector('comboboxAction:'));