2011-09-17 63 views
-6
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. 

選項是TSelectDirOpts =集TSelectDirOpt的;選擇目錄錯誤...德爾福7

TSelectDirOpt標準是{TSelectDirOpt =( sdAllowCreate, sdPerformCreate, sdPrompt )

gFindDirs是一個簡單的變量保持名稱沒有別的,所以我刪除它。 (0)「;如果你有一個錯誤,我會得到一個錯誤:」類Estringlist.error:列表索引超出界限(0)「;我不知道如何解決這個問題。 我嘗試這與JVCL庫的組成部分jvselectdirectory但我得到同樣的事情... 在jvselectdirectory如果我把它清空我去到默認的應用程序文件夾...

這裏是所有的節目.. 。按下按鈕獲取名稱變成我之前創建的現有目錄,並嘗試用selectdirectory打開它它就是我得到上述錯誤... 完整代碼沒有其他創建窗體並將按鈕一個事件onclick() 。

哎呀對不起,我修復它....急於修復錯誤的複製粘貼...... 幫助...

+0

當你運行什麼?您顯示不包含的代碼('OldDirIs'),未引用的變量('gFindDirs'),並將'options'用作'SelectDirectory'的參數,但不顯示設置'選項',然後期望我們解決'EStringList錯誤'異常而不顯示使用'TStringList'的代碼? 「我的車不起作用,我沒有汽車,但是可能是錯的?」請編輯你的問題,使其成爲一個有意義的實際問題。因此,它應該被視爲無稽之談。 –

+1

-1發佈虛假代碼 –

+0

這是有趣的事情我的朋友肯白我不使用任何stringlist錯誤我得到我從selectdirectory得到它... – azrael11

回答

1
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; 

此代碼運行沒有錯誤...(注:改變的getPath - > MyGetPath;添加 「\」 爲 'C:\ Program Files文件')如果公關會徽仍然存在,請在其他地方查看代碼或發佈更多代碼/信息。

+0

我把它的問題仍然存在..我沒有其他代碼只有這個...但從這裏和那裏搜索我發現,也許是德爾福7錯誤我嘗試一些事情,稍後發言,如果你發現別的只是發佈謝謝你Bob A – azrael11

+0

@ azrael11將SelectDirectory更改爲FileCtrl.SelectDirectory ... –

+0

不起作用bob a – azrael11

1

你應該

procedure GetPath(name:string); 
var 
    options : TSelectDirOpts; 
begin 
    FixedOldDirIs(name); //returns olddir 
    gFindDirs := name; 
    if FixedSelectDirectory(OldDir,options,0) then 
    FixedSetPath(gFindDirs); 
end; 

取代你的代碼應該做的招(如果我正確地理解你的問題...)

+0

沒有我的朋友,但謝謝我張貼了一個非常懶惰的帖子...所以謝謝... – azrael11