我在使用DriveComboBox1这个控件的时候,它默认总在我的D盘,每次运行总是D盘,
我想改成E盘。
也就是说每次运行的时候,默认为E盘。
请问如何实现?

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    DriveComboBox1.Drive:='e';
    end;
      

  2.   

    我是指动态实现的:
    我用一个inputbox函数,如果我输入其它的盘符那么下次启动时就会指点那个盘!!!
    procedure TForm1.SpeedButton3Click(Sender: TObject);
      VAR DefaultPath:String;
    begin
      DefaultPath:=InputBox('默认路径','','e:\');
      If DirectoryExists(DefaultPath) Then
         DirectoryListBox1.Directory:=DefaultPath
      Else
         Begin
          MessageBox(Form1.Handle ,'目录不存在!','数据导入程序',MB_Ok);
          Exit;
         End;
    end;
    以下这个方法不行啊!!
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    DriveComboBox1.Drive:='e';
    end;
      

  3.   

    那你把默认的驱动器名写到一个文件里面去
    设置时候写进去
    用的时候取出来
    procedure TForm1.FormCreate(Sender: TObject);
    var
      list:tstringlist;
    begin
      list:=tstringlist.Create;
      list.loadfromfile('drive.dat');
      DriveComboBox1.Drive:=char(strtoint(list.Strings[0]));
      list.free;
    end;procedure TForm1.SpeedButton3Click(Sender: TObject);
    var
      DefaultPath:String;
      list:tstringlist;
      str:string;
    begin
      DefaultPath:=InputBox('默认路径','','e:\');
      If DirectoryExists(DefaultPath) Then
         begin
            list:=tstringlist.Create;
            str:=copy(DefaultPath,1,1);
            list.text:=inttostr(ord(str[length(str)]));
            list.SaveToFile('drive.dat');
            list.free;
            DirectoryListBox1.Directory:=DefaultPath;
         end
      Else
         Begin
          MessageBox(Form1.Handle ,'目录不存在!','数据导入程序',MB_Ok);
          Exit;
         End;
    end;
      

  4.   

    TO:lxer(lxer) 我试了试,“出现找不到drive.dat这个文件!”我是不是有手工建立这个drive.dat这个文件??
    我想让程序自动建立这个文件??
      

  5.   

    要不就这样
    procedure TForm1.FormCreate(Sender: TObject);
    var
      list:tstringlist;
    begin
      list:=tstringlist.Create;
      try 
        list.loadfromfile('drive.dat');
      except
        list.add(inttostr(ord('e')));
        list.SaveToFile('drive.dat');
      end;
      DriveComboBox1.Drive:=char(strtoint(list.Strings[0]));
      list.free;
    end;
      

  6.   

    procedure TForm1.FormCreate(Sender: TObject);Var List:Tstringlist;
    begin
      List:=Tstringlist.Create;
      try
        List.LoadFromFile('DrivePath.dat');
      except
        List.Add('e:\');
        List.LoadFromFile('DrivePath.dat');
      end;
      DirectoryListBox1.Directory:=List.Strings[0];
      List.Free;
    end;还是不行?? 另外我还想问问:
    list.add(inttostr(ord('e'))); ??
    为什不能: list.add(e;\');
      

  7.   

    DriveComboBox1.Drive要的是个char
    比如'e' 'd' 'f' 
    象'e:\'这样当然不行了你按我上面写的不行么?
    用list.add(inttostr(ord('e')));
    不要List.Add('e:\');
    要不就出错了
      

  8.   

    DriveComboBox1.Drive:='e';
    是取现在的DriveComboBox1的驱动器名;
    可以通过改ItemIndex来做
    DriveComboBox1.ItemIndex:=0;