uMapObjectImpl.pas 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. unit uMapObjectImpl;
  2. interface
  3. uses
  4. uIMapObject, uMapObject;
  5. type
  6. TMapObjectImpl = class(TInterfacedObject, IMapObject)
  7. private
  8. FMap: TMapObject;
  9. protected
  10. function getObject(pvKey: string): TObject; stdcall;
  11. procedure removeObject(pvKey: string); stdcall;
  12. procedure setObject(pvKey: string; pvObject: TObject); stdcall;
  13. procedure freeAll(); stdcall;
  14. public
  15. destructor Destroy; override;
  16. procedure AfterConstruction; override;
  17. end;
  18. implementation
  19. destructor TMapObjectImpl.Destroy;
  20. begin
  21. FMap.clear;
  22. FMap.Free;
  23. inherited Destroy;
  24. end;
  25. procedure TMapObjectImpl.freeAll;
  26. var
  27. i:Integer;
  28. begin
  29. for i := FMap.count-1 downto 0 do
  30. begin
  31. try
  32. TObject(FMap.Values[i]).Free;
  33. except
  34. end;
  35. end;
  36. FMap.clear;
  37. end;
  38. { TMapObjectImpl }
  39. procedure TMapObjectImpl.AfterConstruction;
  40. begin
  41. inherited;
  42. FMap := TMapObject.Create;
  43. end;
  44. function TMapObjectImpl.getObject(pvKey: string): TObject;
  45. begin
  46. Result := TObject(FMap.find(pvKey));
  47. end;
  48. procedure TMapObjectImpl.removeObject(pvKey: string);
  49. begin
  50. FMap.remove(pvKey);
  51. end;
  52. procedure TMapObjectImpl.setObject(pvKey: string; pvObject: TObject);
  53. begin
  54. FMap.put(pvKey, pvObject);
  55. end;
  56. end.