doom4ster
2018-01-09 9b90a3164af2997eb141c5c15e3bc1038e31e27b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
unit SortMemo;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls, Buttons,IISunit;
 
type
  TSortMemoForm = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    ComboBox1: TComboBox;
    MemoLV: TListView;
    MsgLb: TLabel;
    AddBt: TButton;
    SaveBt: TButton;
    EraseBt: TButton;
    ExitBt: TButton;
    procedure FormCreate(Sender: TObject);
    procedure MemoLVSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure EraseBtClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ContentList : TStringlist;      //µù°O¤º®e²M³æ
    MemoIDList : TStringlist;       //µù°O¥N¸¹²M³æ
    MemoNameList : TStringlist;     //µù°O¦WºÙ²M³æ
    ResoureMemo : TStringlist;
  end;
 
var
  SortMemoForm: TSortMemoForm;
 
implementation
 
{$R *.dfm}
 
procedure TSortMemoForm.Button1Click(Sender: TObject);
var
  i : Integer;
  iContent,iName : String;
  MemoExitst : Boolean;
begin
  if combobox1.ItemIndex <> -1 then
  begin
    iContent := ContentList.Strings[Combobox1.ItemIndex];
    iName := MemoNameList.Strings[Combobox1.ItemIndex];
  end
  Else
  begin
    if ComboBox1.Text = '' then
    begin
      Showmessage(_Msg('½Ð¿é¤Jµù°O¤º®e'));
      Exit;
    end;
    iContent := ComboBox1.Text;
    iName := _Msg('¦Û¦æ¿é¤J');
  end;
  MemoExitst := False;
  for i := 0 to MemoLV.Items.Count - 1 do
  begin
    if (MemoLV.Items.Item[i].Caption = iContent) and (MemoLV.Items.Item[i].SubItems.Strings[0]=iName) then
    begin
      MemoExitst := True;
      Showmessage(_Msg('µù°O¤v¦s¦b'));
      Exit;
    end;
  end;
  if not MemoExitst then
  begin
    With MemoLV.Items.Add do
    begin
      Caption := iContent;
      Subitems.Add(iName);
    end;
    ComboBox1.ItemIndex := -1;
    ComboBox1.Text := '';
  end;
end;
 
procedure TSortMemoForm.Button2Click(Sender: TObject);
begin
  modalResult := mrok;
end;
 
procedure TSortMemoForm.EraseBtClick(Sender: TObject);
begin
  if MemoLV.Selected <> nil then
  begin
    if MessageDlg(_msg('¬O§_§R°£¦¹µù°O?'),mtConfirmation,[mbyes,mbcancel],0) = mrcancel then
      Exit;
    MemoLV.Selected.Delete;
    Showmessage(_Msg('§R°£§¹¦¨'));
  end;
end;
 
procedure TSortMemoForm.Button4Click(Sender: TObject);
begin
  modalResult := mrcancel;
end;
 
procedure TSortMemoForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
  i : Integer;
  NeedSave : Boolean;
  iContent : String;
begin
  NeedSave := False;
  if ReSoureMemo.Count <> MemoLV.Items.Count then
  begin
    NeedSave := True;
  end
  Else
  begin
    for i := 0 to Resourememo.Count - 1 do
    begin
      iContent := MemoLV.Items.Item[i].SubItems.Strings[0]+'-->'+ MemoLV.Items.Item[i].Caption;
      if ResoureMemo.Strings[i] <> iContent then
      begin
        NeedSave := True;
        Break;
      end;
    end;
  end;
  if (modalResult= mrcancel) and NeedSave then
  begin
    if messagedlg(_Msg('©|¦³­×§ï¥¼Àx¦s,¬O§_©ñ±óÀx¦s'),mtconfirmation,[mbyes,mbcancel],0) = mrCancel Then
    begin
      Action :=  caNone;
      Exit;
    end;
  end;
  Action :=  caFree;
  ResoureMemo.Free;
end;
 
procedure TSortMemoForm.FormCreate(Sender: TObject);
begin
  PostMessage(Handle,WM_ACTIVATE,WA_CLICKACTIVE,0);
  ResoureMemo := TStringlist.Create;
end;
 
procedure TSortMemoForm.MemoLVSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var
  i : Integer;
  S : String;
begin
  ComboBox1.ItemIndex := -1;
  ComboBox1.Text := '';
  if (Item.SubItems.Strings[0] = _Msg('¦Û¦æ¿é¤J')) or (Item.SubItems.Strings[0] = '') then
  begin
    ComboBox1.Text := Item.Caption;
  end
  Else
  begin
    S := Item.SubItems.Strings[0]+'-->'+Item.Caption;
    for i := 0 to ComboBox1.Items.Count - 1 do
    begin
      if S = ComboBox1.Items.Strings[i] then
      begin
        ComboBox1.ItemIndex := i;
        Exit;
      end;
    end;
  end;
end;
 
end.