收集了一些Delphi搜索文件的代碼,覺得挺實用的,分享給大家,代碼裡的注釋不多,不過看上去不太復雜,共同進步吧:
01
unit
Unit1;
02
interface
03
uses
04
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
05
Dialogs, StdCtrls, StrUtils;
06
type
07
TForm1 =
class
(TForm)
08
Edit1: TEdit;
09
Edit2: TEdit;
10
Button1: TButton;
11
procedure
Button1Click(Sender: TObject);
12
private
13
{ Private declarations }
14
public
15
{ Public declarations }
16
end
;
17
var
18
Form1: TForm1;
19
function
FindFlatFileInParentDir(curPath, sFile:
string
):
20
FindFlatFile(curPath, sFile:
21
implementation
22
{$R *.dfm}
23
24
25
pntPath:
26
FilePath:
27
I:
Integer
28
begin
29
pntPath := curPath;
30
While
true
do
31
FilePath := FindFlatFile(pntPath, sFile);
32
if
FilePath <>
''
then
33
Result := FilePath;
34
Break;
35
else
36
Length(pntPath) <=
3
37
RightStr(pntPath,
1
) = '\'
38
Delete(pntPath, length(pntPath),
);
39
for
I := Length(pntPath)
downto
40
pntPath[I] = '\'
41
Delete(pntPath, I, Length(pntPath));
42
43
44
45
46
47
48
49
50
sRec: TSearchRec;
51
sRetCode:
52
sPath:
53
54
FillChar(sRec, SizeOf(sRec), #
0
55
sPath := curPath;
56
RightStr(sPath,
) <> '\'
57
sPath := sPath + '\';
58
sRetCode := FindFirst(sPath +
'*.*'
, faAnyFile, sRec);
59
sRetCode =
60
(sRec
.
Attr
and
not
faDirectory =
)
Name <>
'.'
'..'
61
Result := FindFlatFile(sPath + sRec
Name, sFile)
62
63
AnsIEndsText(sRec
64
Result := sPath + sRec
Name ;
65
66
67
68
69
sRetCode := FindNext(sRec);
70
71
72
TForm1
73
74
Caption := FindFlatFileInParentDir(Edit1
Text, Edit2
Text);
75
76
本例效果圖:代碼文件:unit Unit1;i
本例效果圖: 代碼文件:unit Unit1;inter
本例效果圖: 代碼文件:unit Unit1;inte
一篇 不錯的Delphi游戲編寫教程,實現數字拼圖游戲,包
為什麼是用等待函數來把關? 因為上面幾個等待函數也可以等待