Select Directory error ... delphi 7 [closed]
unit unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,FileCtrl,omnixml,omnixmlutils;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
procedure olddiris(name:string);
procedure GetPath(name:string);
{ Public declarations }
end;
var
Form1: TForm1;
olddir: string; //global variable.
implementation
{$R *.dfm}
procedure Tform1.olddiris(name:string);
begin
if name = 'trick' then
olddir:= 'c:\program files'+name;
end;
procedure Tform1.GetPath(name:string);
var
options : TSelectDirOpts;
begin
OldDirIs(name); //returns olddir
if SelectDirectory(OldDir,options,0) then
ShowMessage('i got it');
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
getpath('trick');
end;
end.
Options is TSelectDirOpts =开发者_如何学编程 set of TSelectDirOpt;
TSelectDirOpt Standard is {TSelectDirOpt = ( sdAllowCreate, sdPerformCreate, sdPrompt )
gFindDirs is a simple variable that keeps the Name nothing else so i erase it. The setPath(gFindDirs) just forget it ok i replace it with a simple massage..
When I run it i get an error: the "class Estringlist.error: List index out of bounds(0)"; I try this with the component jvselectdirectory of jvcl library but I get the same thing... in jvselectdirectory if I left it empty it goes me to the default application folder...
Here is all the program... push the button get the name turn into an existing directory i create before and try to open it with the selectdirectory that's it i get the above error... FULL CODE nothing else create a form and put a button one event onclick().
Oops Sorry i fix it.... The rush to fix it wrong copy paste... Help...
var
olddir: string; //global variable
procedure olddiris(name:string);
begin
if name = 'trick' then
olddir:= 'c:\program files\'+name;
end;
procedure MyGetPath(name:string);
var
options : TSelectDirOpts;
begin
OldDirIs(name); //returns olddir
if FileCtrl.SelectDirectory(OldDir,options,0) then
ShowMessage('i got it');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Mygetpath('trick');
end;
This code runs without error... (Note: changed GetPath -> MyGetPath; added "\" to 'c:\program files') If the problem still exists, look elsewhere in you code or post more code/info.
You should replace your code with
procedure GetPath(name:string);
var
options : TSelectDirOpts;
begin
FixedOldDirIs(name); //returns olddir
gFindDirs := name;
if FixedSelectDirectory(OldDir,options,0) then
FixedSetPath(gFindDirs);
end;
That should do the trick (if I understand your question correctly...)
精彩评论