There are those occasion when we need to populate a list box with file names to subsequently act on one of more of those file names.
With the BCSXE3Utils this is accomplished in one easy statement.
Be sure to watch the video near the end of this post.
[codesyntax lang=”delphi”]
{*----------------------------------------------------------------------------- Procedure: LoadListBox1Click Date: 18-Dec-2013 @Param Sender: TObject @Return None -----------------------------------------------------------------------------} procedure TBCSCopItC.LoadListBox1Click(Sender: TObject); begin; BCSXE3UtilsCmp1.PopulateListBox (BCSXE3UtilsCmp1.GetFileNames(BCSXE3UtilsCmp1.SelADir, '*.bat'), BCSXE3UtilsCmp1.FilLen, ListBox1); end;
[/codesyntax]
Notice the GetFileNames function prompts the user to select a directory and specifiles ‘*.bat’ as the file extension. This yields a traversed list of all available subdirectories from the selected sub directory that contains batch files only.
Once the listbox is populated the further action can be taken as indicated by the example below.
[codesyntax lang=”delphi”]
{*----------------------------------------------------------------------------- Procedure: ListBox1DblClick Date: 18-Dec-2013 @Param Sender: TObject @Return None -----------------------------------------------------------------------------} procedure TBCSCopItC.ListBox1DblClick(Sender: TObject); begin BCSXE3UtilsCmp1.ShellExec(ListBox1.Items[ListBox1.ItemIndex]); end;
[/codesyntax]
As the above code indicates when the listbox item is double clicked the ShellExecute command of BCSXE3Utils is invoked.
This gives the technician a quick and dirty method of acting on a list of files in a listbox.
The source code for BCSXE3Utils is found here http://cc.embarcadero.com/Item/29423.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.