VCL Controls: The File List Box |
|
Introduction |
To assist you with visually getting a list of files inside a directory, the VCL provides an object named the file list box. To get it, in the Win 3.1 section of the Toolbox, click the TFileListBox control and click the form (or other container). In the VCL, this control is represented by a class of the same name. |
|
A file list box is used to show a list of files:
Normally, before uing it, a user should first select a directory, which is not possible in the file list box. To make this possible, you should add a directory list box and possibly a drive combo box:
After adding a directory list box, you should assign the file list box to it to allow the file list box to show the files of the currently selected directory. To support this, the TDirectoryListBox class is equipped with a property named FileList. This property is of type TFileListBox: __property Filectrl::TFileListBox * FileList = {read=FFileList,write=SetFileListBox}; To visually assign the file list box, access the Object Inspector for the directory list box. In the FileList field, select the name of the file list box.
|
Before accessing a file, the user should first select the apppropriate drive in the drive combo box. The drive that is currently selected is identified by the Drive property of the TFileListBox class: __property wchar_t Drive = {read=GetDrive,write=SetDrive}; This property behaves as its counterpart of the directory list box. To use a directory list box, the user can click a directory to select it. When this is happens, the control fires an OnChange event. The file that is currently selected is represented by the FileName prpoperty: __property System::UnicodeString FileName = {read=GetFilePath,write=ApplyFilePath}; To get the complete path and the name of the file that is currently selected, get the value of this property; //--------------------------------------------------------------------------- void __fastcall TForm1::FileListBox1Change(TObject *Sender) { ShowMessage(FileListBox1->FileName); } //---------------------------------------------------------------------------
By contrast, and because TFileListBox::FileName is a read-write property, to select a file, assign its complete path and name to this property. When you do this, make sure you provide a path that exists. Otherwise, you would receive an error. When a file is selected, if you want, you can show its name in an edit box. To suppport this, the TFileListBox class is equipped with a property named EditFile: __property Stdctrls::TEdit * FileEdit = {read=FFileEdit,write=SetFileEdit}; To visually use this property, add a TEdit control to your form. On the form, select the file list box. In the Object Inspector, select the name of the edit box in the EditFile field.
|
|
|||||||
|
|
||
Home | Copyright © 2010-2016, FunctionX | |
|