FMXTOpenDialog (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example shows how to use the TOpenDialog filters to show only certain files in the dialog.

To build and test this example, create a Multi-Device Application - C++ Builder, and add the following on the form:

  • A TOpenDialog object to display the dialog that chooses what file(s) to open.
  • A TComboBox object used for selecting which types of files are shown in the newly opened dialog.
  • A TButton to trigger the Execute property of the TOpenDialog object.
  • Three TListBoxItems that filter the TOpenDialog results. These can be added manually from the Items Designer menu, accessible by double-clicking the TComboBox component.
  • A TLabel that displays the following text: "Select File Type:".


Before writing the code, add the FMX.Media.hpp unit scope in the header file, at the includes section. Also, rename the three TListBoxItems to Text, Multimedia and Image.

void __fastcall TForm4::Button1Click(TObject *Sender) {
	if (Text->IsSelected) {
		// Shows text files only.
		OpenDialog1->Filter = "Text Files (*.txt)|*.txt";
	else if (Image->IsSelected) {
		// Shows image files only.
		OpenDialog1->Filter = TBitmapCodecManager::GetFilterString();
	else if (Multimedia->IsSelected) {
		// Shows audio/video files only.
		OpenDialog1->Filter = TMediaCodecManager::GetFilterString();
		// Select a type of file from the TComboBox.
			ShowMessage("Select a type of file");