action.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************}
  12. {* TBasicActionLink *}
  13. {****************************************************************************}
  14. constructor TBasicActionLink.Create(AClient: TObject);
  15. begin
  16. inherited Create;
  17. AssignClient(AClient);
  18. end;
  19. procedure TBasicActionLink.AssignClient(AClient: TObject);
  20. begin
  21. end;
  22. destructor TBasicActionLink.Destroy;
  23. begin
  24. if FAction <> nil then
  25. FAction.UnRegisterChanges(Self);
  26. inherited Destroy;
  27. end;
  28. procedure TBasicActionLink.Change;
  29. begin
  30. if Assigned(OnChange) then
  31. OnChange(FAction);
  32. end;
  33. function TBasicActionLink.Execute(AComponent: TComponent): Boolean;
  34. begin
  35. FAction.ActionComponent := AComponent;
  36. try
  37. Result := FAction.Execute;
  38. finally
  39. if FAction <> nil then
  40. FAction.ActionComponent := nil;
  41. end;
  42. end;
  43. procedure TBasicActionLink.SetAction(Value: TBasicAction);
  44. begin
  45. if Value <> FAction then
  46. begin
  47. if FAction <> nil then FAction.UnRegisterChanges(Self);
  48. FAction := Value;
  49. if Value <> nil then Value.RegisterChanges(Self);
  50. end;
  51. end;
  52. function TBasicActionLink.IsOnExecuteLinked: Boolean;
  53. begin
  54. Result := True;
  55. end;
  56. procedure TBasicActionLink.SetOnExecute(Value: TNotifyEvent);
  57. begin
  58. end;
  59. function TBasicActionLink.Update: Boolean;
  60. begin
  61. Result := FAction.Update;
  62. end;
  63. {****************************************************************************}
  64. {* TBasicAction *}
  65. {****************************************************************************}
  66. constructor TBasicAction.Create(AOwner: TComponent);
  67. begin
  68. inherited Create(AOwner);
  69. FClients := TList.Create;
  70. end;
  71. destructor TBasicAction.Destroy;
  72. begin
  73. inherited Destroy;
  74. while FClients.Count > 0 do
  75. UnRegisterChanges(TBasicActionLink(FClients.Last));
  76. FClients.Free;
  77. end;
  78. function TBasicAction.HandlesTarget(Target: TObject): Boolean;
  79. begin
  80. Result := False;
  81. end;
  82. procedure TBasicAction.ExecuteTarget(Target: TObject);
  83. begin
  84. end;
  85. procedure TBasicAction.UpdateTarget(Target: TObject);
  86. begin
  87. end;
  88. function TBasicAction.Execute: Boolean;
  89. begin
  90. if Assigned(FOnExecute) then
  91. begin
  92. FOnExecute(Self);
  93. Result := True;
  94. end
  95. else
  96. Result := False;
  97. end;
  98. function TBasicAction.Update: Boolean;
  99. begin
  100. if Assigned(FOnUpdate) then
  101. begin
  102. FOnUpdate(Self);
  103. Result := True;
  104. end
  105. else
  106. Result := False;
  107. end;
  108. procedure TBasicAction.SetOnExecute(Value: TNotifyEvent);
  109. var
  110. I: Integer;
  111. begin
  112. if (TMethod(Value).Code <> TMethod(OnExecute).Code) or
  113. (TMethod(Value).Data <> TMethod(OnExecute).Data) then
  114. begin
  115. for I := 0 to FClients.Count - 1 do
  116. TBasicActionLink(FClients[I]).SetOnExecute(Value);
  117. FOnExecute := Value;
  118. Change;
  119. end;
  120. end;
  121. procedure TBasicAction.Change;
  122. begin
  123. if Assigned(FOnChange) then
  124. FOnChange(Self);
  125. end;
  126. procedure TBasicAction.RegisterChanges(Value: TBasicActionLink);
  127. begin
  128. Value.FAction := Self;
  129. FClients.Add(Value);
  130. end;
  131. procedure TBasicAction.UnRegisterChanges(Value: TBasicActionLink);
  132. var
  133. I: Integer;
  134. begin
  135. for I := 0 to FClients.Count - 1 do
  136. if TBasicActionLink(FClients[I]) = Value then
  137. begin
  138. Value.FAction := nil;
  139. FClients.Delete(I);
  140. break;
  141. end;
  142. end;
  143. {
  144. $Log$
  145. Revision 1.1 2003-10-06 21:01:06 peter
  146. * moved classes unit to rtl
  147. Revision 1.1 2002/01/06 21:54:49 peter
  148. * action classes added
  149. }