Table of Contents

TXlsFile.GetObjectSelection Method

Gets the selected item in an object from the "Forms" palette. It can be a combobox or a listbox. 0 means no selection, 1 the first item in the list. Note that this only works for objects added through the Forms toolbar. It won't return the values of ActiveX objects.

Remarks

Note that if the object is linked to a cell and you changed the cell value, this method will return the cell value.

Syntax

Unit: FlexCel.XlsAdapter

function TXlsFile.GetObjectSelection(const objectIndex: Integer; const objectPath: string): Integer; override;

Parameters

<-> Parameter Type Description
const objectIndex Integer Index of the object (1 based)
const objectPath string Index to the child object you want to change the property.
If it is a simple object, you can use String.Empty here, if not you need to get the ObjectPath from TExcelFile.GetObjectProperties(Integer, Boolean)
If it is "absolute"(it starts with "\"), then the path includes the objectIndex, and the objectIndex is not used. An object path of "\1\2\3" is exactly the same as using objectIndex = 1 and objectPath = "2\3"

Returns

The position of the selected item in the object. 0 means no selection, 1 the first item is selected.

Examples

To get all the comboboxes in the active sheet, you can use this code:

var
  xls: TXlsFile;
  i: Int32;
  shp: IShapeProperties;
begin
  xls := TXlsFile.Create('comboboxes.xls');  //Open the file we want to read.
  try
    for i := 1 to xls.ObjectCount do  //Loop over all objects.
    begin
      shp := xls.GetObjectProperties(i, false);
      if shp.ObjectType = TObjectType.ComboBox then  //Is it a combobox?
      begin
        LogMessage(shp.Text + ' :' + IntToStr(xls.GetObjectSelection(i, '')));  //Log the state of the combobox
      end;

    end;
  finally
    xls.Free;
  end;
end;

See also