Getting the bin index from the Bins stringlist

Category

Code Based - General

Question

I want to save off the currently selected bin name and need to be able to know the bin index into the Bins string list in order to get the name. How would I do this?

Solution

The following code will enable you to get the index into the bins string list, which contains the names of the available bins. You can use the GetBinIndex method along with the Bins property to determine the name of the currently selected bin.

Delphi Example:

uses
  RPDevice;

function GetBinIndex: integer;
var
  DefSource: smallint;
  i1: integer;

begin
  Result := -1;// bin not in list
  DefSource := RPDev.DevMode.dmDefaultSource;
  for i1 := 0 to RPDev.Bins.Count -1 do begin
    if DefSource = integer(RPDev.Bins.Objects[i1]) then begin
      Result := i1;
      Exit;
    end;
  end; { for }
end;

C++Builder Example:

int __fastcall TForm1::GetBinIndex()
{
  int DefSource = RPDev()->DevMode->dmDefaultSource;
  for (int i1 = 0; i1 < RPDev()->Bins->Count; i1++) {
    if (DefSource == (int) RPDev()->Bins->Objects[i1]) {
      return i1;
    }// if
  }// for
  return -1;// bin not in list
}