我要实现在窗口A中点击一个按钮,就可以打开目录对话框,选择相应目录后,回到原窗口
A,原窗口A的edit中可以获取相应的路径。试过使用文件对话框,但是选择的是文件,用directorylistbox建立另一个窗口,又会存在窗口A调用窗口B,然后窗口B调用窗口A,系统报错。可以怎么实现这个目录选择对话框?各位帮帮忙,给源码亚

解决方案 »

  1.   

    uses
      FileCtrl;procedure TForm1.Button1Click(Sender: TObject);
    var
      Directory: string;
    begin
      if SelectDirectory('选择目录', '', Directory) then
        Edit1.Text := Directory;
    end;
      

  2.   

    please choose...Project ----> Import Type Library--->Microsoft Shell Controls and Automations(version 1.0)---> click 'Install' button to install TShell 
    Example1
     
    1. Drop TButton componet to Form1
    2. Drop TShell component from 'ActiveX' table to Form1
    3. --------------------------------------
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleServer, shlobj, Shell32_TLB;type
      TForm1 = class(TForm)
        Shell1: TShell;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
       Shell1.BrowseForFolder(self.Handle, 'Choose directory to search', BIF_EDITBOX, ssfDESKTOP);
    end;end.