TCurFlagItem = class(TObject) //定义一个ITEM对象,用来存储ITEM;
Flag:Integer;
Clocked:Boolean;
Note:string;
end;
TCurFlag=class(TStringList) //定义一个LIST型对象,用来处理上面的ITEM;
private
{ Private declarations }
FItemIndex: Integer;
FClocked: Boolean;
FFlag: Integer;
FNote: string;
FOnItemIndexChange: TNotifyEvent;
procedure SetClocked(const Value: Boolean);
procedure SetFlag(const Value: Integer);
procedure SetNote(const Value: string);
procedure SetItemIndex(const Value: Integer); //在这里挂上事件处理;
protected
public
{ Public declarations }
property Flag:Integer read FFlag write SetFlag;
property Clocked:Boolean read FClocked write SetClocked;
property Note:string read FNote write SetNote;
property ItemIndex:Integer read FItemIndex write SetItemIndex;
Function AddItem(Flag:Integer;Note:string):Boolean;
property OnItemIndexChange: TNotifyEvent read FOnItemIndexChange write FOnItemIndexChange; //定义事件
procedure ChangeItemIndexUp;
procedure ChangeItemIndexDown;
published
end;
............................................................................
{ TCurFlag }
function TCurFlag.AddItem(Flag: Integer;Note: string): Boolean;
var
curFlagItem:TCurFlagItem;
begin
try
curFlagItem:=TCurFlagItem.Create;
curFlagItem.Flag:=Flag;
curFlagItem.Clocked:=False;
curFlagItem.Note:=Note;
Self.AddObject('BiSoftWare',curFlagItem);
Result:=True;
except
Result:=False;
end;
end;
procedure TCurFlag.ChangeItemIndexDown;
begin
ry
CurFlagItem:=TCurFlagItem(self.Objects[FItemIndex]);
FFlag:=CurFlagItem.Flag;
FClocked:=CurFlagItem.Clocked;
FNote:=CurFlagItem.Note;
if Assigned(FOnItemIndexChange) then //这里是关键;当ItemIndex改变时,触发自定义的事件;这里也就是一个挂事件的过程;
FOnItemIndexChange(Self);
finally
end;
end;
procedure TCurFlag.SetNote(const Value: string);
begin
FNote := Value;
end;
使用实例:
........................................................................
CurFlag:TCurFlag;
//首先定义好事件过程;
procedure CurFlagOnItemIndexChange(Sender: TObject);
...............................................................................
CurFlag:=TCurFlag.Create;
//将事件过程挂到实例的OnItemIndexChange处理中
CurFlag.OnItemIndexChange:=CurFlagOnItemIndexChange%3�
FOnItemIndexChange(Self);
finally
end;
end;
procedure TCurFlag.SetNote(const Value: string);
begin
FNote := Value;
end;
使用实例:
........................................................................
CurFlag:TCurFlag;
//首先定义好事件过程;
procedure CurFlagOnItemIndexChange(Sender: TObject);
...............................................................................
CurFlag:=TCurFlag.Create;
//将事件过程挂到实例的OnItemIndexChange处理中
CurFlag.OnItemIndexChange:=CurFlagOnItemIndexChange;
请发表评论