I am getting a list of Application Pools and then populating the combo box with the names of app pools. The problem is that when when the OnDropDown
event is called the combo box opens for a fraction of a second and then closes straight away. It does not remain "dropped down". I do see all the app pools in the combo box. Here is my code:
function GetApplicationPoolList() : TArrayOfString;
var
i, nExitCode: Integer;
sFileLines: TArrayOfString;
sTempFileName, sListAppPoolCmd: String;
begin
sListAppPoolCmd := ExpandConstant('{sys}') + '\inetsrv\appcmd list apppool /text:name';
sTempFileName := ExpandConstant('{tmp}') + '\appPoolList.txt';
if not ExecAppCmd(Format('%s > %s',[sListAppPoolCmd, sTempFileName]), nExitCode) then begin
MsgBox('Could not get app pools', mbError, MB_OK);
end else begin
LoadStringsFromFile(sTempFileName, sFileLines);
end
Result := sFileLines;
end;
// ==============================================
procedure OnAppPoolComboBoxDropDown(Sender: TObject);
var
sAppPoolList: TArrayOfString;
i: Integer;
begin
// Clear existing
appPoolComboBox.Items.Clear;
// Populate the combo box with the application pools
sAppPoolList := GetApplicationPoolList;
For i := 0 to GetArrayLength (sAppPoolList) - 1 do
begin
// ComboBox with Application Pool Names
appPoolComboBox.Items.Add(sAppPoolList[i]);
end;
appPoolComboBox.ItemIndex := 0;
end;
function ExecAppCmd(params :String; nExitCode: Integer) :Boolean;
var
execSuccessfully :Boolean;
resultCode :Integer;
begin
execSuccessfully := Exec('cmd.exe', '/c ' + '' + ' ' + params, '', SW_HIDE, ewWaitUntilTerminated, resultCode);
nExitCode := resultCode;
Result := execSuccessfully and (resultCode = 0);
end;
I am not sure what is happening here. Any advice is appreciated.
EDIT: ExecAppCmd
seems to be the issue, commenting it out makes the combo box behave normally... Though not sure why
The drop-down closes probably because the combo box loses focus momentarily as the application is starting.
I'd say it's a bad practice to call an application on drop-down, as it takes time and it ruins a user experience. Populate the combo box earlier, like from CurPageChanged
.