Separate Letters from a string and add to a Combobox

Asked

Viewed 135 times

3

Searching the web I found this function to returns the letters of the Hdds.

function tbDriveLetters: string;
{ Uso: S := tbDriveLetters; - retorna 'ACD' se existir as unidades A:, C: e D: }
var
  Drives: LongWord;
  I: byte;
begin
  Result := '';
  Drives := GetLogicalDrives;

  if Drives <> 0 then
    for I := 65 to 90 do
      if ((Drives shl (31 - (I - 65))) shr 31) = 1 then
        Result := Result + Char(I);
end;

I need another function to separate the letters and add to the Combobox so that each Letter is a Combobox item.

1 answer

4


Instead of doing the process through a function, you can popular the ComboBox directly.

procedure tbDriveLetters;
{Uso: S := tbDriveLetters; - retorna 'ACD' se existir as unidades A:, C: e D:}
var
  Drives: LongWord;
  I: byte;
begin
  Drives := GetLogicalDrives;

  if Drives <> 0 then
    for I := 65 to 90 do
      if ((Drives shl (31 - (I - 65))) shr 31) = 1 then
        ComboBox.Itens.Add(Char(I));
end;

But, if you really need it to be done by function, imagining it to be in different Units, you can modify the Return of your function which is String for a Tcombobox.

That is, you can return an already populated Tcombobox to the component that the client will use on the screen.

Building:

function tbDriveLetters:TComboBox;

Feeding:

Result.Itens.Add(Char(I));

Attribution:

SeuComboBox := tbDriveLetters;
  • I took the test and I’m fine...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.