1{%MainUnit ../actnlist.pas} 2 3{ 4 ***************************************************************************** 5 This file is part of the Lazarus Component Library (LCL) 6 7 See the file COPYING.modifiedLGPL.txt, included in this distribution, 8 for details about the license. 9 ***************************************************************************** 10} 11 12 13{ TContainedAction } 14 15destructor TContainedAction.Destroy; 16begin 17 if ActionList <> nil then ActionList.RemoveAction(Self); 18 inherited Destroy; 19end; 20 21function TContainedAction.GetIndex: Integer; 22begin 23 if ActionList <> nil then 24 Result := ActionList.FActions.IndexOf(Self) 25 else 26 Result := -1; 27end; 28 29function TContainedAction.GetParentComponent: TComponent; 30begin 31 if ActionList <> nil then 32 Result := ActionList 33 else 34 Result := inherited GetParentComponent; 35end; 36 37function TContainedAction.HasParent: Boolean; 38begin 39 if ActionList <> nil then 40 Result := True 41 else 42 Result := inherited HasParent; 43end; 44 45procedure TContainedAction.ReadState(Reader: TReader); 46begin 47 inherited ReadState(Reader); 48 if Reader.Parent is TCustomActionList then 49 ActionList := TCustomActionList(Reader.Parent); 50end; 51 52procedure TContainedAction.SetIndex(Value: Integer); 53var 54 CurIndex, Count: Integer; 55begin 56 CurIndex := GetIndex; 57 if CurIndex >= 0 then 58 begin 59 Count := ActionList.FActions.Count; 60 if Value < 0 then Value := 0; 61 if Value >= Count then Value := Count - 1; 62 if Value <> CurIndex 63 then ActionList.FActions.Move(CurIndex, Value); 64 end; 65end; 66 67procedure TContainedAction.SetCategory(const Value: string); 68begin 69 if Value <> Category then 70 begin 71 FCategory := Value; 72 if ActionList <> nil then 73 ActionList.Change; 74 end; 75end; 76 77procedure TContainedAction.SetActionList(NewActionList: TCustomActionList); 78begin 79 if NewActionList <> ActionList then 80 begin 81 if ActionList <> nil then ActionList.RemoveAction(Self); 82 // FActionList is set by AddAction 83 if NewActionList <> nil then NewActionList.AddAction(Self); 84 end; 85end; 86 87procedure TContainedAction.SetParentComponent(AParent: TComponent); 88begin 89 if not (csLoading in ComponentState) and (AParent is TCustomActionList) then 90 ActionList := TCustomActionList(AParent); 91end; 92 93function TContainedAction.Execute: Boolean; 94begin 95 Result := ((ActionList <> nil) and ActionList.ExecuteAction(Self)) 96 or ((ApplicationActionComponent<>nil) 97 and ApplicationActionComponent.ExecuteAction(Self)) 98 or (inherited Execute) 99 or (SendApplicationMessage(CM_ACTIONEXECUTE, 0, PtrInt(Self)) = 1); 100end; 101 102function TContainedAction.Update: Boolean; 103begin 104 Result := ((ActionList <> nil) and ActionList.UpdateAction(Self)) 105 or ((ApplicationActionComponent<>nil) 106 and ApplicationActionComponent.UpdateAction(Self)) 107 or (inherited Update) 108 or (SendApplicationMessage(CM_ACTIONUPDATE, 0, PtrInt(Self)) = 1); 109end; 110 111// included by actnlist.pas 112