全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2608
推到 Plurk!
推到 Facebook!

FINDFIRST的檔案排序問題

答題得分者是:william
stonys
初階會員


發表:64
回覆:111
積分:38
註冊:2002-09-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-09 12:37:35 IP:61.59.xxx.xxx 未訂閱
各位先進好,我使用了findfirst這個函數要搜尋資料夾下面的檔案 然後如果找到的話,就將檔名寫入memo中 如: if firstfirst(path:\*.*,faanyfile,f)=0 then memo1.line.add(f.name) 可是不知道為何?每次寫入的順序都跟從檔案總管看到的不同 想請教一下,如果想讓搜尋出來的結果按照檔名,或是檔案大小,或是附檔名之類的排序該如何做到呢?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-09 14:26:49 IP:147.8.xxx.xxx 未訂閱
I think you need to sort it yourself, e.g. 1) store all TSearchRec in a TList 2) perform a sort on the list, e.g. List1.Sort(SortMethod) 3) loop through the list and update the memo
stonys
初階會員


發表:64
回覆:111
積分:38
註冊:2002-09-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-09 17:47:54 IP:61.59.xxx.xxx 未訂閱
謝謝版主的回應 我現在也是用這種方法來先作排序 可是這麼一來,只能排序"檔名" 如果我想針對"檔案大小" or"屬性"...之類作排序 該如何做呢?
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-10 09:53:37 IP:147.8.xxx.xxx 未訂閱
Resort the list and update the memo?    Assume you have all TSearchRec stored in List1, i.e. List1.Items[0] is a PSearchRec (=^TSearchRec), then    
{ sorting function for attribute }
function AttrSort(p1,p2: pointer): integer;
begin
    if PSearchRec(p1)^.Attr < PSearchRec(p2)^.Attr then
        Result := -1
    else if PSearchRec(p1)^.Attr = PSearchRec(p2)^.Attr then
        Result := 0
    else
        Result := 1;
end;
{...}
List1.Sort(AttrSort);
{ update the memo }
stonys
初階會員


發表:64
回覆:111
積分:38
註冊:2002-09-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-04-10 20:57:47 IP:61.59.xxx.xxx 未訂閱
版主大大,謝謝您的回應    可是在下小弟我的程式功力沒那麼好,您的有些用法小弟我看不大懂    能否請稍微解釋一下程式碼的用途呢?謝謝!    EX: ^是做什麼用的呢?請教^^
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-04-11 09:08:12 IP:147.8.xxx.xxx 未訂閱
^ means dereferencing the pointer.. PSearchRec(p1)^.Attr means typcase the pointer p1 as PSearchRec and get the Attr member of the TSearchRec to which it is pointing. TList has a sort method (using quick sort) and you need to supply you own comparing method (e.g. AttrSort) or it.
stonys
初階會員


發表:64
回覆:111
積分:38
註冊:2002-09-28

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-04-11 21:10:19 IP:211.74.xxx.xxx 未訂閱
謝謝您...
系統時間:2024-06-28 17:53:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!