开发者

Select Directory error ... delphi 7 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.
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...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜