TDriveComboBox和TDirectoryListBox控件与创建文件的问题我在from2中用了TDriveComboBox和TDirectoryListBox这两个控件,然后再到from1中创建文件就不能了!写也不能!from1和from2的关系是1调用2,如果我执行程序时不调用from2的话就可以创建文件或写文件!请大家帮帮忙!急急急呀!from2中遍历目录的代码是这样的!//我做的是个播放器,
procedure TForm2.ButtonXPMACCorel1Click(Sender: TObject);
var
i:integer;
searchRec:TsearchRec;
seat:string;
begin   ///dlb为 TDirectoryListBox类
  filepa:=dlb.GetItemPath(dlb.ItemIndex);///得到选择目录的路径
  filepa:=filepa+'\';
//showmessage(filepa);
  for i:=0 to 3 do
  begin
  if i=0 then seat:='*.mp3';
  if i=1 then seat:='*.wav';
  if i=2 then seat:='*.mpeg';
  if i=3 then seat:='*.mid';
    if (FindFirst(filepa+seat, faAnyFile-faDirectory, SearchRec)=0)  then
    begin
      Form1.ListBox2.Items.Add(filepa+searchrec.Name);
     if i<>3 then
      ///添加到from1中的listbox中去,GetNameFromTag()为读文件信息的函数
      Form1.ListBox1.Items.Add(GetNameFromTag(filepa+searchrec.Name))
     ////namer()也是读文件信息的函数
     else Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name));
      while (FindNext(SearchRec) = 0) do
      begin
      Form1.ListBox2.Items.Add(filepa+searchrec.Name);
     if i<>3 then
      Form1.ListBox1.Items.Add(GetNameFromTag(filepa+searchrec.Name))
     else Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name));
      end;
    end;
    FindClose(SearchRec);
    Dcb.Free;
    Dlb.Free;
  end;
  close;
end;请问是这里什么没有释放的吗?我真的找不出哪里出问题了!给位老大帮忙啊!

解决方案 »

  1.   

    Dcb.Free;
        Dlb.Free;
    你是动态创建的吗?而且CREATE(NIL)?
    如果你是放到窗体上就不需要FREE这里。
    另外你的两个////namer()也是读文件信息的函数
    有没有CLOSEFILE啊;
      

  2.   

    都试过了!没有问题!就是不知道问题出在哪里!我把所有的代码全部:unit Unit2;interfaceuses
      Windows,Forms, SysUtils, Variants, Classes, Controls, StdCtrls,
      FileCtrl, ButtonXPMACCorel ;type
      TForm2 = class(TForm)
        DCB: TDriveComboBox;
        ButtonXPMACCorel1: TButtonXPMACCorel;
        ButtonXPMACCorel2: TButtonXPMACCorel;
        DLB: TDirectoryListBox;
        procedure FormShow(Sender: TObject);
        procedure ButtonXPMACCorel2Click(Sender: TObject);
        procedure ButtonXPMACCorel1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        filepa:string;
      end;var
      Form2: TForm2;implementationuses Unit1;
    type
      TMP3Tag = record
        idTAG : array [0..2] of Char;
        idSongName :array [0..29] of Char;
        idArtist :array [0..29] of Char;
      end;{$R *.dfm}procedure TForm2.FormShow(Sender: TObject);
    begin
      filepa:='';
    end;procedure TForm2.ButtonXPMACCorel2Click(Sender: TObject);
    begin
    close;
    end;
    function namer(mp3file:string):string;
    var
    i:integer;
    filename:string;
    begin
      filename:='';
      for i:=length(mp3file) downto 1 do
      begin
        if (mp3file[i]='\') then break;
      end;
      filename:=copy(mp3file,i+1,length(mp3file));
      Result:=filename;
    end;function GetNameFromTag(Mp3File:TFileName):string;
    var
      Mp3Stream : TFileStream;
      ID3       : TMP3Tag;
      j:integer;
      s:string;
    begin
    try
      ZeroMemory(@ID3,SizeOf(ID3));
      Mp3Stream := TFileStream.Create(Mp3File,fmOpenRead);
      Mp3Stream.Seek(-128, soFromEnd);
      Mp3Stream.Read(ID3, SizeOf(ID3));
      Mp3Stream.Free;
    //  showmessage(mp3file+id3.idTAG+id3.idSongName+id3.idArtist);
      if ID3.idTAG ='TAG' then
      begin
        if Trim(ID3.idArtist)='' then
        begin
         if Trim(ID3.idSongName)='' then Result :='未知的--'+ namer(Mp3File)
          else Result:='未知的--'+ Trim(ID3.idSongName);
         end
          else
           begin
            if Trim(ID3.idSongName)='' then
              begin
                j:=length(id3.idArtist);
                s:=copy(namer(mp3File),1,j);
                if (id3.idArtist=s) then
                  Result:=namer(mp3file)
                else
                  Result := Trim(ID3.idArtist) + '--' + namer(Mp3File);
              end
            else Result := Trim(ID3.idArtist) + '--' +Trim(ID3.idSongName);
            end;
    //    if UpperCase(ExtractFileExt(Result)) <> '.MP3' then Result := Result + '.mp3';
      end
      else Result :='未知的--'+namer(Mp3File);
    except
     Result :='未知的--'+namer(Mp3File);
    end;
    end;
    procedure TForm2.ButtonXPMACCorel1Click(Sender: TObject);
    var
    i:integer;
    searchRec:TsearchRec;
    seat:string;
    begin
      filepa:=dlb.GetItemPath(dlb.ItemIndex);
      filepa:=filepa+'\';
    //showmessage(filepa);
      for i:=0 to 3 do
      begin
      if i=0 then seat:='*.mp3';
      if i=1 then seat:='*.wav';
      if i=2 then seat:='*.mpeg';
      if i=3 then seat:='*.mid';
        if (FindFirst(filepa+seat, faAnyFile-faDirectory, SearchRec)=0)  then
        begin
          Form1.ListBox2.Items.Add(filepa+searchrec.Name);
         if i<>3 then
          Form1.ListBox1.Items.Add(GetNameFromTag(filepa+searchrec.Name))
         else Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name));
          while (FindNext(SearchRec) = 0) do
          begin
          Form1.ListBox2.Items.Add(filepa+searchrec.Name);
         if i<>3 then
          Form1.ListBox1.Items.Add(GetNameFromTag(filepa+searchrec.Name))
         else Form1.ListBox1.Items.Add(namer(filepa+searchrec.Name));
          end;
        end;
        FindClose(SearchRec);
      end;
      close;
    end;end.
      

  3.   

    换个控件吧!用TSHELLTREEVIEW!