TOpenDialogFileName (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

Use a TOpenDialog to select a file. Place the first line of the file into a TEdit. Click the text edit to open the dialog box.

Code

procedure TForm1.Edit1Click(Sender: TObject);
var
  F: TextFile;
  S: string;
begin
  if OpenDialog1.Execute then            { Display Open dialog box. }
  begin
    AssignFile(F, OpenDialog1.FileName); { File selected in the dialog }
    Reset(F);
    Readln(F, S);                        { Read the first line of the file }
    Edit1.Text := S;                     { Put string in a TEdit control. }
    CloseFile(F);
  end;
end;

Uses

Personal tools
Assistance