OSDN Git Service

9fb843e751e6ee087d60ed5ce091526265a2c9e4
[gikonavigoeson/gikonavi.git] / IndividualAbon.pas
1 unit IndividualAbon;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7   Dialogs, StdCtrls, Buttons;
8
9 type
10   TIndividualAbonForm = class(TForm)
11     ComboBox1: TComboBox;
12     Label1: TLabel;
13     Button1: TButton;
14     BitBtn1: TBitBtn;
15     procedure Button1Click(Sender: TObject);
16   private
17         { Private \90é\8c¾ }
18         FThreadLogFileName: String;
19         FNGFileName: String;
20   public
21         { Public \90é\8c¾ }
22         FRepaint : boolean;
23         ResNumber : Integer;
24         function SetThreadLogFileName(AFileName: String): boolean;
25         function DeleteNG(AResNum: Integer): boolean;
26   end;
27
28 var
29   IndividualAbonForm: TIndividualAbonForm;
30
31 implementation
32
33 {$R *.dfm}
34
35 procedure TIndividualAbonForm.Button1Click(Sender: TObject);
36 var
37         NGFile: TStringList;
38         i, j: Integer;
39
40         str: String;
41 begin
42         if (FileExists(FNGFileName)) and (ComboBox1.ItemIndex >= 0) then begin
43                 NGFile := TStringList.Create;
44                 try
45                         try
46                                 NGFile.LoadFromFile(FNGFileName);
47                                 str := ComboBox1.Items[ComboBox1.ItemIndex] + '-';
48                                 i := -1;
49                                 for j := 0 to NGFile.Count - 1 do begin
50                                         if AnsiPos(str, NGFile[j]) = 1 then begin
51                                                 i := j;
52                                                 break;
53                                         end;
54                                 end;
55
56                                 //i := NGFile.IndexOf(str);
57                                 if i >= 0 then begin
58                                         FRepaint := true;
59                                         NGFile.Delete(i);
60                                         if NGFile.Count = 0 then
61                                                 DeleteFile(FNGFileName)
62                                         else
63                                                 NGFile.SaveToFile(FNGFileName);
64                                 end else
65                                         FRepaint := false;
66                         except
67                         end;
68                 finally
69                         NGFile.Free;
70                 end;
71         end;
72 end;
73 function TIndividualAbonForm.SetThreadLogFileName(AFileName: String): boolean;
74 var
75         NGFile: TStringList;
76         i: Integer;
77         str: String;
78 begin
79         FThreadLogFileName := AFileName;
80         FNGFileName := ChangeFileExt(AFileName, '.NG');
81         Result := false;
82         if FileExists(FNGFileName) then begin
83                 NGFile := TStringList.Create;
84                 try
85                         try
86                                 NGFile.LoadFromFile(FNGFileName);
87                                 ComboBox1.Items.Clear;
88                                 for i := 0 to NGFile.Count - 1do begin
89                                         str := Copy(NGFile.Strings[i], 1, AnsiPos('-', NGFile.Strings[i]) - 1);
90                                         if str <> '' then
91                                                 ComboBox1.Items.Add(str);
92                                 end;
93                                 if ComboBox1.Items.Count > 0 then
94                                         Result := true;
95                         except
96                                 Result := false;
97                         end;
98                 finally
99                         NGFile.Free;
100                 end;
101         end;
102 end;
103 function TIndividualAbonForm.DeleteNG(AResNum: Integer): boolean;
104 var
105         NGFile: TStringList;
106         i, j: Integer;
107
108         str: String;
109 begin
110         Result := false;
111         if (FileExists(FNGFileName)) and (AResNum > 0) then begin
112                 NGFile := TStringList.Create;
113                 try
114                         try
115                                 NGFile.LoadFromFile(FNGFileName);
116                                 str := IntToStr(AResNum) + '-';
117                 i := -1;
118                                 for j := 0 to NGFile.Count - 1 do begin
119                                         if AnsiPos(str, NGFile[j]) = 1 then begin
120                                                 i := j;
121                                                 break;
122                                         end;
123                                 end;
124                                 if i >= 0 then begin
125                                         Result := true;
126                                         NGFile.Delete(i);
127                                         if NGFile.Count = 0 then
128                                                 DeleteFile(FNGFileName)
129                                         else
130                                                 NGFile.SaveToFile(FNGFileName);
131                                 end;
132                         except
133                         end;
134                 finally
135                         NGFile.Free;
136                 end;
137         end;
138 end;
139
140 end.