#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    86
    Rep Power
    13

    Loading a drive combobox from DirPath?


    Hi, I have a config file that records a directory path:

    i.e. C:\Users\Greg\StuffIwantToAccess


    I'm using a DriveComboBox and DirectoryListBox, basically I want to load the last known Drive letter and directory into both of the components... I have to say I did not see this taking more then a few seconds till I discovered that the driveComboBox only likes a "char"

    So how to I convert a string to a char?

    This is my code:

    Code:
    procedure TfWorkingDir.FormActivate(Sender: TObject);
    var
    conf_working_drive,dirLetter : string;
      begin
      conf_working_drive := ExtractFileDrive(pub_conf.Values['working_dir_conf']);
      dirLetter := copy(conf_working_drive,1,(length(conf_working_drive) -1)) ;
      showmessage(dirLetter);//Returns a single character but of "string"
    
      fWorkingDir.DriveComboBox1.Drive := dirLetter;//ERROR here: Incompatible types string vs char
      end;
    end.
    I've done a bit of research on this but all the solutions seem ridiculously complex, surely they should not be? If they are then so be it but I thought I'd check here first...

    PS: if you have a better solution than a drive combo box and directory list box please let me know, this solution feels so Windows 3.1 to me :-P

    Thanks!!

    Greg.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Try this:
    Code:
    procedure TfWorkingDir.FormActivate(Sender: TObject);
    var
    conf_working_drive : string;
    dirLetter: Char;
      begin
      conf_working_drive := ExtractFileDrive(pub_conf.Values['working_dir_conf']);
      dirLetter := conf_working_drive[1];
      showmessage(dirLetter);//Returns a single character but of "string"
    
      fWorkingDir.DriveComboBox1.Drive := dirLetter;
      end;
    end.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    86
    Rep Power
    13
    Thank you Clive!

    I didn't realize that strings were one dimensional arrays in Delphi.

IMN logo majestic logo threadwatch logo seochat tools logo