線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1808
推到 Plurk!
推到 Facebook!

判為是否為資料夾的問題??

答題得分者是:boss.tw
2007
中階會員


發表:54
回覆:90
積分:98
註冊:2008-08-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-01-16 14:12:47 IP:220.132.xxx.xxx 未訂閱
各位大大好:
為什麼資料夾是設成這樣子,sSearchRec.Attr 就不等於 faDirectory ???
sSearchRec.Attr = 48 (0x30) <--抓到的 sSearchRec.Attr 值

http://delphi.ktop.com.tw/download/upload/4970255f832b8_圖片1.JPG



if( sSearchRec.Attr==faDirectory )
{
........................
}

請問要怎麼正確的判斷它是否為資料夾??
謝謝


附加檔案:4970255f832b8_圖片1.JPG
編輯記錄
2007 重新編輯於 2009-01-16 14:13:28, 註解 無‧
boss.tw
高階會員


發表:15
回覆:109
積分:194
註冊:2005-05-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-01-16 21:22:18 IP:122.116.xxx.xxx 訂閱

[code cpp]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TSearchRec sr;
int iAttributes = 0;
StringGrid1->RowCount = 1;
iAttributes |= faReadOnly * CheckBox1->Checked;
iAttributes |= faHidden * CheckBox2->Checked;
iAttributes |= faSysFile * CheckBox3->Checked;
iAttributes |= faVolumeID * CheckBox4->Checked;
iAttributes |= faDirectory * CheckBox5->Checked;
iAttributes |= faArchive * CheckBox6->Checked;
iAttributes |= faAnyFile * CheckBox7->Checked;
StringGrid1->RowCount = 0;
if (FindFirst(Edit1->Text, iAttributes, sr) == 0)

{
do
{
if ((sr.Attr & iAttributes) == sr.Attr)
{
StringGrid1->RowCount = StringGrid1->RowCount 1;
StringGrid1->Cells[1][StringGrid1->RowCount-1] = sr.Name;
StringGrid1->Cells[2][StringGrid1->RowCount-1] = IntToStr(sr.Size);
}
} while (FindNext(sr) == 0);
FindClose(sr);
}
}
[/code]
wjhsu
初階會員


發表:9
回覆:32
積分:48
註冊:2004-06-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-01-23 12:33:27 IP:61.219.xxx.xxx 訂閱
因為faDirectory是bit mask,
如果你只是要判斷是否為資料夾,
只要判斷對應的bit就好
例如

[code cpp]
if( (SearchRec.Attr & faDirectory) != 0)
{...}
[/code]

TSearchRec 的說明裏也有...
To test for an attribute, combine the value of the Attr field with the attribute constant with the and operator.
系統時間:2024-04-20 7:30:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!