[829] | 1 | unit VAClasses;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Controls, Classes, SysUtils, Types, RTLConsts;
|
---|
| 7 |
|
---|
| 8 | type
|
---|
| 9 | TVABaseMethodList = class(TObject)
|
---|
| 10 | strict private
|
---|
| 11 | FCode: TList;
|
---|
| 12 | FData: TList;
|
---|
| 13 | strict protected
|
---|
| 14 | function GetMethod(index: integer): TMethod;
|
---|
| 15 | property Code: TList read FCode;
|
---|
| 16 | property Data: TList read FData;
|
---|
| 17 | protected
|
---|
| 18 | constructor Create; virtual;
|
---|
| 19 | function IndexOf(const Method: TMethod): integer;
|
---|
| 20 | procedure Add(const Method: TMethod);
|
---|
| 21 | procedure Clear;
|
---|
| 22 | function Count: integer;
|
---|
| 23 | procedure Delete(index: integer);
|
---|
| 24 | procedure Remove(const Method: TMethod);
|
---|
| 25 | property Methods[index: integer]: TMethod read GetMethod; default;
|
---|
| 26 | public
|
---|
| 27 | destructor Destroy; override;
|
---|
| 28 | end;
|
---|
| 29 |
|
---|
| 30 | TVAMethodList = class(TVABaseMethodList)
|
---|
| 31 | public
|
---|
| 32 | constructor Create; override;
|
---|
| 33 | destructor Destroy; override;
|
---|
| 34 | function IndexOf(const Method: TMethod): integer;
|
---|
| 35 | procedure Add(const Method: TMethod);
|
---|
| 36 | procedure Clear;
|
---|
| 37 | function Count: integer;
|
---|
| 38 | procedure Delete(index: integer);
|
---|
| 39 | procedure Remove(const Method: TMethod);
|
---|
| 40 | property Methods;
|
---|
| 41 | end;
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | TVALinkedMethodList = class(TVABaseMethodList)
|
---|
| 45 | private
|
---|
| 46 | FLinkedObjects: TList;
|
---|
| 47 | public
|
---|
| 48 | constructor Create; override;
|
---|
| 49 | destructor Destroy; override;
|
---|
| 50 | procedure Add(Obj: TObject; const Method: TMethod);
|
---|
| 51 | function IndexOf(const obj: TObject): integer;
|
---|
| 52 | procedure Clear;
|
---|
| 53 | function Count: integer;
|
---|
| 54 | procedure Delete(index: integer);
|
---|
| 55 | procedure Remove(const obj: TObject); overload;
|
---|
| 56 | function GetMethod(Obj: TObject): TMethod;
|
---|
| 57 | // property Methods;
|
---|
| 58 | end;
|
---|
| 59 |
|
---|
| 60 | // event fires before the component has acted on the notification
|
---|
| 61 | TVANotifyEvent = procedure(AComponent: TComponent; Operation: TOperation) of object;
|
---|
| 62 |
|
---|
| 63 | TVANotificationEventComponent = class(TComponent)
|
---|
| 64 | private
|
---|
| 65 | FOnNotifyEvent: TVANotifyEvent;
|
---|
| 66 | protected
|
---|
| 67 | procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
---|
| 68 | public
|
---|
| 69 | constructor NotifyCreate(AOwner: TComponent; AOnNotifyEvent: TVANotifyEvent); virtual;
|
---|
| 70 | property OnNotifyEvent: TVANotifyEvent read FOnNotifyEvent write FOnNotifyEvent;
|
---|
| 71 | end;
|
---|
| 72 |
|
---|
| 73 | TVAListChangeEvent = procedure(Sender: TObject; Item: Pointer; Operation: TOperation) of object;
|
---|
| 74 |
|
---|
| 75 | TVAList = class(TList)
|
---|
| 76 | private
|
---|
| 77 | FOnChange: TVAListChangeEvent;
|
---|
| 78 | protected
|
---|
| 79 | procedure Notify(Ptr: Pointer; Action: TListNotification); override;
|
---|
| 80 | published
|
---|
| 81 | property OnChange: TVAListChangeEvent read FOnChange write FOnChange;
|
---|
| 82 | end;
|
---|
| 83 |
|
---|
| 84 | const
|
---|
| 85 | DynaPropAccesibilityCaption = 1;
|
---|
| 86 |
|
---|
| 87 | type
|
---|
| 88 | IVADynamicProperty = interface(IInterface)
|
---|
| 89 | ['{1D1620E9-59D1-475D-94E9-FAE89A601D55}']
|
---|
| 90 | function SupportsDynamicProperty(PropertyID: integer): boolean;
|
---|
| 91 | function GetDynamicProperty(PropertyID: integer): string;
|
---|
| 92 | end;
|
---|
| 93 |
|
---|
| 94 | implementation
|
---|
| 95 |
|
---|
| 96 | { TVABaseMethodList }
|
---|
| 97 |
|
---|
| 98 | procedure TVABaseMethodList.Add(const Method: TMethod);
|
---|
| 99 | begin
|
---|
| 100 | if IndexOf(Method) < 0 then
|
---|
| 101 | begin
|
---|
| 102 | FCode.Add(Method.Code);
|
---|
| 103 | FData.Add(Method.Data);
|
---|
| 104 | end;
|
---|
| 105 | end;
|
---|
| 106 |
|
---|
| 107 | procedure TVABaseMethodList.Clear;
|
---|
| 108 | begin
|
---|
| 109 | FCode.Clear;
|
---|
| 110 | FData.Clear;
|
---|
| 111 | end;
|
---|
| 112 |
|
---|
| 113 | function TVABaseMethodList.Count: integer;
|
---|
| 114 | begin
|
---|
| 115 | Result := FCode.Count;
|
---|
| 116 | end;
|
---|
| 117 |
|
---|
| 118 | constructor TVABaseMethodList.Create;
|
---|
| 119 | begin
|
---|
| 120 | FCode := TList.Create;
|
---|
| 121 | FData := TList.Create;
|
---|
| 122 | end;
|
---|
| 123 |
|
---|
| 124 | procedure TVABaseMethodList.Delete(index: integer);
|
---|
| 125 | begin
|
---|
| 126 | FCode.Delete(index);
|
---|
| 127 | FData.Delete(index);
|
---|
| 128 | end;
|
---|
| 129 |
|
---|
| 130 | destructor TVABaseMethodList.Destroy;
|
---|
| 131 | begin
|
---|
| 132 | FreeAndNil(FCode);
|
---|
| 133 | FreeAndNil(FData);
|
---|
| 134 | inherited;
|
---|
| 135 | end;
|
---|
| 136 |
|
---|
| 137 | function TVABaseMethodList.GetMethod(index: integer): TMethod;
|
---|
| 138 | begin
|
---|
| 139 | Result.Code := FCode[index];
|
---|
| 140 | Result.Data := FData[index];
|
---|
| 141 | end;
|
---|
| 142 |
|
---|
| 143 | function TVABaseMethodList.IndexOf(const Method: TMethod): integer;
|
---|
| 144 | begin
|
---|
| 145 | if assigned(Method.Code) and assigned(Method.data) and (FCode.Count > 0) then
|
---|
| 146 | begin
|
---|
| 147 | Result := 0;
|
---|
| 148 | while((Result < FCode.Count) and ((FCode[Result] <> Method.Code) or
|
---|
| 149 | (FData[Result] <> Method.Data))) do inc(Result);
|
---|
| 150 | if Result >= FCode.Count then Result := -1;
|
---|
| 151 | end
|
---|
| 152 | else
|
---|
| 153 | Result := -1;
|
---|
| 154 | end;
|
---|
| 155 |
|
---|
| 156 | procedure TVABaseMethodList.Remove(const Method: TMethod);
|
---|
| 157 | var
|
---|
| 158 | idx: integer;
|
---|
| 159 |
|
---|
| 160 | begin
|
---|
| 161 | idx := IndexOf(Method);
|
---|
| 162 | if(idx >= 0) then
|
---|
| 163 | begin
|
---|
| 164 | FCode.Delete(idx);
|
---|
| 165 | FData.Delete(idx);
|
---|
| 166 | end;
|
---|
| 167 | end;
|
---|
| 168 |
|
---|
| 169 | { TVAMethodList }
|
---|
| 170 |
|
---|
| 171 | procedure TVAMethodList.Add(const Method: TMethod);
|
---|
| 172 | begin
|
---|
| 173 | inherited Add(Method);
|
---|
| 174 | end;
|
---|
| 175 |
|
---|
| 176 | procedure TVAMethodList.Clear;
|
---|
| 177 | begin
|
---|
| 178 | inherited Clear;
|
---|
| 179 | end;
|
---|
| 180 |
|
---|
| 181 | function TVAMethodList.Count: integer;
|
---|
| 182 | begin
|
---|
| 183 | Result := inherited Count;
|
---|
| 184 | end;
|
---|
| 185 |
|
---|
| 186 | constructor TVAMethodList.Create;
|
---|
| 187 | begin
|
---|
| 188 | inherited Create;
|
---|
| 189 | end;
|
---|
| 190 |
|
---|
| 191 | procedure TVAMethodList.Delete(index: integer);
|
---|
| 192 | begin
|
---|
| 193 | inherited Delete(index);
|
---|
| 194 | end;
|
---|
| 195 |
|
---|
| 196 | destructor TVAMethodList.Destroy;
|
---|
| 197 | begin
|
---|
| 198 | inherited;
|
---|
| 199 | end;
|
---|
| 200 |
|
---|
| 201 | function TVAMethodList.IndexOf(const Method: TMethod): integer;
|
---|
| 202 | begin
|
---|
| 203 | Result := inherited IndexOf(Method);
|
---|
| 204 | end;
|
---|
| 205 |
|
---|
| 206 | procedure TVAMethodList.Remove(const Method: TMethod);
|
---|
| 207 | begin
|
---|
| 208 | inherited Remove(Method);
|
---|
| 209 | end;
|
---|
| 210 |
|
---|
| 211 | { TVANotificationEventComponent }
|
---|
| 212 |
|
---|
| 213 | procedure TVANotificationEventComponent.Notification(AComponent: TComponent;
|
---|
| 214 | Operation: TOperation);
|
---|
| 215 | begin
|
---|
| 216 | if assigned(FOnNotifyEvent) then FOnNotifyEvent(AComponent, Operation);
|
---|
| 217 | inherited;
|
---|
| 218 | end;
|
---|
| 219 |
|
---|
| 220 | constructor TVANotificationEventComponent.NotifyCreate(AOwner: TComponent;
|
---|
| 221 | AOnNotifyEvent: TVANotifyEvent);
|
---|
| 222 | begin
|
---|
| 223 | inherited Create(AOwner);
|
---|
| 224 | FOnNotifyEvent := AOnNotifyEvent;
|
---|
| 225 | end;
|
---|
| 226 |
|
---|
| 227 | { TVALinkedMethodList }
|
---|
| 228 |
|
---|
| 229 | procedure TVALinkedMethodList.Add(Obj: TObject; const Method: TMethod);
|
---|
| 230 | begin
|
---|
| 231 | if assigned(obj) and assigned(Method.Code) and (IndexOf(Obj) < 0) then
|
---|
| 232 | begin
|
---|
| 233 | FLinkedObjects.Add(Obj);
|
---|
| 234 | Code.Add(Method.Code);
|
---|
| 235 | Data.Add(Method.Data);
|
---|
| 236 | end;
|
---|
| 237 | end;
|
---|
| 238 |
|
---|
| 239 | procedure TVALinkedMethodList.Clear;
|
---|
| 240 | begin
|
---|
| 241 | FLinkedObjects.Clear;
|
---|
| 242 | Code.Clear;
|
---|
| 243 | Data.Clear;
|
---|
| 244 | end;
|
---|
| 245 |
|
---|
| 246 | function TVALinkedMethodList.Count: integer;
|
---|
| 247 | begin
|
---|
| 248 | Result := FLinkedObjects.Count;
|
---|
| 249 | end;
|
---|
| 250 |
|
---|
| 251 | constructor TVALinkedMethodList.Create;
|
---|
| 252 | begin
|
---|
| 253 | inherited;
|
---|
| 254 | FLinkedObjects := TList.Create;
|
---|
| 255 | end;
|
---|
| 256 |
|
---|
| 257 | procedure TVALinkedMethodList.Delete(index: integer);
|
---|
| 258 | begin
|
---|
| 259 | FLinkedObjects.Delete(index);
|
---|
| 260 | Code.Delete(index);
|
---|
| 261 | Data.Delete(index);
|
---|
| 262 | end;
|
---|
| 263 |
|
---|
| 264 | destructor TVALinkedMethodList.Destroy;
|
---|
| 265 | begin
|
---|
| 266 | FreeAndNil(FLinkedObjects);
|
---|
| 267 | inherited;
|
---|
| 268 | end;
|
---|
| 269 |
|
---|
| 270 | function TVALinkedMethodList.GetMethod(Obj: TObject): TMethod;
|
---|
| 271 | var
|
---|
| 272 | idx: integer;
|
---|
| 273 | begin
|
---|
| 274 | idx := IndexOf(Obj);
|
---|
| 275 | if idx < 0 then
|
---|
| 276 | begin
|
---|
| 277 | Result.Code := nil;
|
---|
| 278 | Result.Data := nil;
|
---|
| 279 | end
|
---|
| 280 | else
|
---|
| 281 | Result := Methods[idx];
|
---|
| 282 | end;
|
---|
| 283 |
|
---|
| 284 | function TVALinkedMethodList.IndexOf(const obj: TObject): integer;
|
---|
| 285 | begin
|
---|
| 286 | if assigned(obj) then
|
---|
| 287 | Result := FLinkedObjects.IndexOf(obj)
|
---|
| 288 | else
|
---|
| 289 | Result := -1;
|
---|
| 290 | end;
|
---|
| 291 |
|
---|
| 292 | procedure TVALinkedMethodList.Remove(const obj: TObject);
|
---|
| 293 | var
|
---|
| 294 | i: integer;
|
---|
| 295 | begin
|
---|
| 296 | i := IndexOf(obj);
|
---|
| 297 | if i >= 0 then
|
---|
| 298 | Delete(i);
|
---|
| 299 | end;
|
---|
| 300 |
|
---|
| 301 | { TVAList }
|
---|
| 302 |
|
---|
| 303 | procedure TVAList.Notify(Ptr: Pointer; Action: TListNotification);
|
---|
| 304 | begin
|
---|
| 305 | if assigned(FOnChange) and (Ptr <> nil) then
|
---|
| 306 | begin
|
---|
| 307 | if Action = lnAdded then
|
---|
| 308 | FOnChange(Self, Ptr, opInsert)
|
---|
| 309 | else
|
---|
| 310 | FOnChange(Self, Ptr, opRemove)
|
---|
| 311 | end;
|
---|
| 312 | end;
|
---|
| 313 |
|
---|
| 314 | end.
|
---|