1

現在、Excel ファイルを Delphi にロードする方法について、このチュートリアルを少し変更しようとしています。ファイル パスを取得し、ファイルをテキスト ボックスにロードして接続手順を起動する後続の手順を開始するために、OpenDialog を使用したいと考えています。以下のコードの下書きを作成しましたが、ファイルをコンパイルしてボタンをクリックした後に注意が必要です。私の理解では、ボタンをクリックすると、開いているファイル ウィンドウが表示されるはずです。ファイルを選択するウィンドウが表示されない理由がわかりません。

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;
4

1 に答える 1