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.