I do not quite understand what you need, if you want to get the file name, then OpenDialog has the FileName property, which contains the full file name. And in order to open any files (including those without an extension), write the star property of the OpenDialog component in the Filter property of the OpenDialog component or leave it empty. If, you just need the name of the file without the path to it, then for this there is a function ExtractFileName, but I don’t know the functions for removing the extension. A similar question is seen here 1 . Or, alternatively, you can use string functions: Copy (<String>, <Number of the character from which to start copying>, <How many characters to copy>) and Pos (<Substring>, <String>).
I wrote this code:
procedure TForm1.btn1Click(Sender: TObject); Var FName: String; begin If Not(dlgOpen1.Execute) Then Exit; FName:=ExtractFileName(dlgOpen1.FileName); If (Pos('.', FName)<>0) Then FName:=Copy(FName, 1, Pos('.', FName)-1); btn1.Caption:=FName; end;
Instead of the Pos function, you can use AnsiPos.