Monday, March 3, 2014

Load Dialog


 1.For this tutorial add a memo, a button and a TOpenDialog in the form.

2.Change the caption of  button1 to "load".
3.Double click on load button and write onclick event: 

procedure TForm1.Button1Click(Sender: TObject);
var
  filename: string;
begin


if OpenDialog1.Execute then
   begin
        filename := OpenDialog1.Filename;
        memo1.Lines.LoadFromFile(opendialog1.FileName);
   end;
end;  



the selected file opens in memo1


4.The Execute method displays the file open dialog.  It returns true when user has selected a file, false when user has aborted.

The Filename property returns the full filename. 

 

5.Look at the object inspector for further options

we can also set the default extension for our file and

add a filter which allow only .txt types to be saved.


so we add the follow lines in form create event 


openDialog1.DefaultExt := 'txt';
openDialog1.Filter := 'Text file|*.txt';

 

Thats all.

No comments:

Post a Comment