自做了一个SpeedButton,用来调用一个路径选择的窗体!unit SelectFilePath;interfaceuses
  SysUtils, Classes, Controls, Buttons, StdCtrls;type
  TSelectFilePath = class(TSpeedButton)
  private
    { Private declarations }
    aEdit: TEdit;
  protected
    { Protected declarations }
    Constructor Create(AOwner: TComponent); Override;
    Destructor Destory;
  public
    { Public declarations }
    sFilePath : String;  
    procedure Click; Override;
  published
    { Published declarations }
  end;procedure Register;implementationuses Unit_Selectfile;procedure Register;
begin
  RegisterComponents('Antique', [TSelectFilePath]);
end;
{ TSelectFilePath }constructor TSelectFilePath.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//  aEdit := TEdit.Create(AOwner); //  ----  在创建speedbutton的同时,想创建一个Edit,用来显示选择的路径信息
//  aEdit.Parent := self.Parent;
end;destructor TSelectFilePath.Destory;
begin  inherited;
end;procedure TSelectFilePath.Click;
begin
  inherited;
  Frm_SelectFile := TFrm_SelectFile.Create(nil);
  try
    Frm_SelectFile.ShowModal;
    sFilePath := Frm_SelectFile.sFilePath;
  finally
    Frm_SelectFile.Free;
  end;end;end.也就是这个控件由一个Edit 和  一个 SpeedButton组成
说来惭愧,编了两年了,组件技术也只是刚涉及!
还有一个问题就是得到的sFilePath 怎么样来取得,比如说程序里的单击事件怎么写?

解决方案 »

  1.   

    摘抄的,你看看吧
    在uses中加入shlobjprocedure TForm1.Button1Click(Sender: TObject);
    var
      tmp: string;
      udtBI: TBrowseInfo;
      lpIDList: Pointer;
      dn: PChar;
    begin
      with udtBI do
        begin
          hWndOwner:=handle;
          iImage:=0;
          lParam:=0;
          lpfn:=nil;
          lpszTitle:='打开文件';
          pidlRoot:=nil;
          ulFlags:=BIF_ReturnOnlyFSdirs;
        end;
      lpIDList:=SHBrowseForFolder(udtBI);
      if assigned(lpIDList) then
        begin
          SetLength(tmp,100);
          SHGetPathFromIDList(lpIDList,PChar(tmp));
          Edit1.text:=tmp;
        end;
    end;