开发者

Delphi open file with standard windows GUI window

开发者 https://www.devze.com 2023-04-04 18:24 出处:网络
I want to be able to open files in Delphi with a Windows GUI where you can scroll through the folders etc. I have already done this with Matlab with a single function that (after selecting the file) r

I want to be able to open files in Delphi with a Windows GUI where you can scroll through the folders etc. I have already done this with Matlab with a single function that (after selecting the file) returns a string of the path. You could event specify which extension the be shown. Is this kind of function开发者_开发问答 available in delphi and how should I use it.


you can use the TOpenDialog component which is part of the Dialogs unit. you can create in runtime or drop this component from the Dialogs palette.

if you drop the component to your form you can use in this way

 OpenDialog1.Filter := 'Only Text files (*.txt)|*.txt';
 if OpenDialog1.Execute then
  //do you stuff here

or if you create the component in runtime

Var
  OpenDialog1 : TOpenDialog;
begin
 OpenDialog1:=TOpenDialog.Create(nil);
 try
   OpenDialog1.Filter := 'Only Text files (*.txt)|*.txt';
   if OpenDialog1.Execute then
    ShowMessage('Selected File '+OpenDialog1.FileName);
 finally
   OpenDialog1.Free;
 end;

end;


That's available via TOpenDialog which encapsulates the relevant Windows functionality.

Drop a TOpenDialog component on your form. Then you can call OpenDialog1.Execute to show the Windows dialog.

0

精彩评论

暂无评论...
验证码 换一张
取 消