I'm currently trying to slightly modify this tutorial on loading the Excel file into Delphi. I would like to use OpenDialog in order to get the file path and start subsequent procedures loading the file to the text box and launching the connecting procedures. I drafted the code below but noting happens after compiling the file and clicking on the button. My understanding is that clicking on the button should show the open file window. I do not understand why the window with the file selection is not coming up.
procedure TForm1.Button1Click(Sender: TObject);
var
openDialog : TOpenDialog; // Open dialog variable
strConn : WideString; // Declare wide string for the connection
begin
// Create the open dialog object - assign to our open dialog variable
openDialog := TOpenDialog.Create(self);
// Set up the starting directory to be the current one
openDialog.InitialDir := GetCurrentDir;
// Only allow existing files to be selected
openDialog.Options := [ofFileMustExist];
// Allow only .Excel and .pas files to be selected
openDialog.Filter :=
'Excel 2003|*.xls|Excel 2007 and newer|*.xlsx';
// Select pascal files as the starting filter type
openDialog.FilterIndex := 2;
// Give file path to the edit
Edit1.Text := openDialog.FileName;
// Connect the Excel file
AdoConnection1.Connected:=False;
AdoConnection1.ConnectionString:=strConn;
end;