對紅色之條件運算式不了解其意思? 知道的朋友能否說明一下 |
答題得分者是:syntax
|
vbkiller
一般會員 ![]() ![]() 發表:65 回覆:28 積分:18 註冊:2007-03-13 發送簡訊給我 |
procedure TForm1.Button1Click(Sender: TObject);
var sr: TSearchRec; FileAttrs: Integer; begin StringGrid1.RowCount := 1; if CheckBox1.Checked then FileAttrs := faReadOnly else FileAttrs := 0; if CheckBox2.Checked then FileAttrs := FileAttrs faHidden; if CheckBox3.Checked then FileAttrs := FileAttrs faSysFile; if CheckBox4.Checked then FileAttrs := FileAttrs faVolumeID; if CheckBox5.Checked then FileAttrs := FileAttrs faDirectory; if CheckBox6.Checked then FileAttrs := FileAttrs faArchive; if CheckBox7.Checked then FileAttrs := FileAttrs faAnyFile; with StringGrid1 do begin RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin repeat if (sr.Attr and FileAttrs) = sr.Attr then begin RowCount := RowCount 1; Cells[1,RowCount-1] := sr.Name; Cells[2,RowCount-1] := IntToStr(sr.Size); end; until FindNext(sr) <> 0; FindClose(sr); end; end; end; | ||||||||||||||||
st33chen
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:15 回覆:591 積分:1201 註冊:2005-09-30 發送簡訊給我 |
|||||||||||||||||
RootKit
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:16 回覆:358 積分:419 註冊:2008-01-02 發送簡訊給我 |
|||||||||||||||||
AndrewK
高階會員 ![]() ![]() ![]() ![]() 發表:6 回覆:151 積分:161 註冊:2006-10-09 發送簡訊給我 |
你可以查一下 TSearchRec 的 Help 說明
把上面的值轉成二進位看待,再去思考以下程式碼所代表的意義 if (sr.attr and faReadOnly ) = faReadOnly
------
Just Do It ------------------------- 其實男生不是真的喜歡你不減肥,而是喜歡你愛吃還不肥;也不是真的喜歡你不化妝,而是喜歡你素顏也好看;也不是真的喜歡你瘦,而是喜歡你瘦卻有胸;也不是真喜歡你獨立,而是他忙的時候別煩他。女孩子,太認真你就輸了。 |
||||||||||||||||
syntax
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:26 回覆:1139 積分:1258 註冊:2002-04-23 發送簡訊給我 |
(sr.Attr and FileAttrs) = sr.Attr
(A and B) = C 表示 A 與 B 做 And 運算後的結果,是否等於 C C 可以是 A 或是 B,或是都不是的另一個數值 至於 And 運算是什麼,請自己 google 或看書(計算計概論) 如 if (011 and 010) = 101 或 if (011 and 010) = 010 或 if (011 and 010) = 011 可以用來做過濾,或是看其一是否包含有另一數值, A, B 誰先誰後並不完全,還需要考慮 C 程式碼的整體意義來看,是在判斷 sr.Attr 是否包含/在範圍內 FileAttrs 如果以「包含」的觀點,C 是應該使用 FileAttrs (sr.Attr and FileAttrs) = FileAttrs ,程式解釋成,如果檔案屬性包含 xxx (我們指定的 FileAttrs),就列出其名稱 如果以「在範圍內」的觀點來看,C 可以使用 sr.Attr (sr.Attr and FileAttrs) = sr.Attr,程式解釋成,如果檔案屬性包含於 FileAttrs 內,就列出其名稱 兩種使用時機與意義不同 ===================引 用 vbkiller 文 章=================== procedure TForm1.Button1Click(Sender: TObject); var sr: TSearchRec; FileAttrs: Integer; begin StringGrid1.RowCount := 1; if CheckBox1.Checked then FileAttrs := faReadOnly else FileAttrs := 0; if CheckBox2.Checked then FileAttrs := FileAttrs faHidden; if CheckBox3.Checked then FileAttrs := FileAttrs faSysFile; if CheckBox4.Checked then FileAttrs := FileAttrs faVolumeID; if CheckBox5.Checked then FileAttrs := FileAttrs faDirectory; if CheckBox6.Checked then FileAttrs := FileAttrs faArchive; if CheckBox7.Checked then FileAttrs := FileAttrs faAnyFile; with StringGrid1 do begin RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin repeat if (sr.Attr and FileAttrs) = sr.Attr then begin RowCount := RowCount 1; Cells[1,RowCount-1] := sr.Name; Cells[2,RowCount-1] := IntToStr(sr.Size); end; until FindNext(sr) <> 0; FindClose(sr); end; end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |