Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit4.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations) (download) (as text)
Mon Jul 27 13:44:42 2015 UTC (8 years, 8 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 2618 byte(s)
最初のコミット
1 yamat0jp 1 unit Unit4;
2    
3     interface
4    
5     uses
6     System.Classes, System.SysUtils;
7    
8     type
9     TSearchMP3 = class(TThread)
10     private
11     { Private 宣言 }
12     protected
13     procedure Execute; override;
14     end;
15    
16     implementation
17    
18     {
19     重要: ビジュアル コンポーネントにおけるオブジェクトのメソッドとプロパティは、Synchronize を使って
20     呼び出されるメソッドでのみ使用できます。たとえば、次のようになります。
21    
22     Synchronize(UpdateCaption);
23    
24     UpdateCaption は、たとえば次のようなコードになります。
25    
26     procedure TSeachMP3.UpdateCaption;
27     begin
28     Form1.Caption := 'スレッドで更新されました';
29     end;
30    
31     あるいは
32    
33     Synchronize(
34     procedure
35     begin
36     Form1.Caption := '無名メソッドを通じてスレッドで更新されました'
37     end
38     )
39     );
40    
41     ここでは、無名メソッドが渡されています。
42    
43     同様に、開発者は上記と同じようなパラメータで Queue メソッドを呼び出すことができます。
44     ただし、別の TThread クラスを第 1 パラメータとして渡し、呼び出し元のスレッドを
45     もう一方のスレッドでキューに入れます。
46    
47     }
48    
49     uses Unit2, Unit1, Unit3;
50    
51     { TSearchMP3 }
52    
53     procedure TSearchMP3.Execute;
54     var
55     list: TStringList;
56     depth: integer;
57     i, k: integer;
58     procedure Add(const Dir: string);
59     var
60     s1, s2: TSearchRec;
61     st: string;
62     i, j: integer;
63     begin
64     if Dir = '' then
65     st := ''
66     else
67     st := IncludeTrailingPathDelimiter(Dir);
68     i := FindFirst(st + '*', faDirectory, s1);
69     j := FindFirst(st + '*.mp3', faAnyFile, s2);
70     try
71     while i = 0 do
72     begin
73     if (s1.Name <> '.') and (s1.Name <> '..') then
74     list.Add(st + s1.Name + '|' + (depth + 1).ToString);
75     i := FindNext(s1);
76     end;
77     while j = 0 do
78     begin
79     Synchronize(
80     procedure
81     begin
82     with Form1.ListView1.Items.Add do
83     begin
84     Text := s2.Name;
85     Detail := st + s2.Name;
86     end;
87     end);
88     j := FindNext(s2);
89     end;
90     finally
91     FindClose(s1);
92     FindClose(s2);
93     end;
94     end;
95    
96     begin
97     { スレッドとして実行したいコードをここに記述してください }
98     list := TStringList.Create;
99     try
100     list.NameValueSeparator := '|';
101     list.Add('|0');
102     i := Form2.PopupBox1.Text.ToInteger;
103     k := 0;
104     while (Terminated = false) and (k < list.Count) do
105     begin
106     depth := list.ValueFromIndex[k].ToInteger;
107     if depth < Trunc(i) then
108     Add(list.Names[k]);
109     inc(k);
110     end;
111     finally
112     list.Free;
113     end;
114     Synchronize(
115     procedure
116     begin
117     Form3.Hide;
118     Form1.Action2Execute(Self);
119     end);
120     end;
121    
122     end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26