FilterIndex (Delphi)
Description
This example uses an Open dialog box, a memo, and a button on a form. When you click the button, the Open dialog box appears. When you select files in the dialog box and choose the OK button, the first line from each of the files is added to the memo. Choose multiple files using the CTRL key or the SHIFT key.
Code
procedure TForm1.Button1Click(Sender: TObject);
var
I: integer;
F: TextFile;
FirstLine: string;
begin
OpenDialog1.Options := [ofAllowMultiSelect, ofFileMustExist];
OpenDialog1.Filter := 'Text files (*.txt)|*.txt|All files (*.*)|*.*';
OpenDialog1.FilterIndex := 2; { Start the dialog showing all files. }
if OpenDialog1.Execute then
with OpenDialog1.Files do
for I := 0 to Count - 1 do
begin
AssignFile(F, Strings[I]); { Next file in the Files property. }
Reset(F);
Readln(F, FirstLine); { Read the first line out of the file }
Memo1.Lines.Append(FirstLine); { Add the line to the memo. }
CloseFile(F);
end;
end;
Uses
- Vcl.Dialogs.TOpenDialog.FilterIndex ( fr | de | ja )
- Vcl.Dialogs.TOpenDialog.Files ( fr | de | ja )
- System.Classes.TStrings.Strings ( fr | de | ja )
- System.Classes.TStrings.Append ( fr | de | ja )