IdMessageCollection.pas 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10263: IdMessageCollection.pas
  11. {
  12. { Rev 1.1 14/07/2004 21:55:12 CCostelloe
  13. { Changed Get/SetMessage to Get/SetIdMessage to avoid conflict under C++ with
  14. { Windows' GetMessage
  15. }
  16. {
  17. { Rev 1.0 2002.11.12 10:46:32 PM czhower
  18. }
  19. unit IdMessageCollection;
  20. {*
  21. TIdMessageCollection: Contains a collection of IdMessages.
  22. 2000-APR-14 Peter Mee: Converted to Indy.
  23. 2001-MAY-03 Idan Cohen: Added Create and Destroy of TIdMessage.
  24. Originally by Peter Mee.
  25. *}
  26. interface
  27. uses
  28. Classes,
  29. IdMessage;
  30. type
  31. TIdMessageItems = class of TIdMessageItem;
  32. TIdMessageItem = class(TCollectionItem)
  33. protected
  34. FAttempt: Integer;
  35. FQueued: Boolean;
  36. public
  37. IdMessage: TIdMessage;
  38. property Attempt: Integer read FAttempt write FAttempt;
  39. property Queued: Boolean read FQueued write FQueued;
  40. constructor Create(Collection: TCollection); override;
  41. destructor Destroy; override;
  42. end;
  43. TIdMessageCollection = class(TCollection)
  44. private
  45. function GetIdMessage(index: Integer): TIdMessage;
  46. procedure SetIdMessage(index: Integer; const Value: TIdMessage);
  47. public
  48. function Add: TIdMessageItem;
  49. property Messages[index: Integer]: TIdMessage read GetIdMessage write SetIdMessage; Default;
  50. end;
  51. implementation
  52. function TIdMessageCollection.Add;
  53. begin
  54. Result := TIdMessageItem(inherited Add);
  55. end;
  56. { TIdMessageItem }
  57. constructor TIdMessageItem.Create;
  58. begin
  59. inherited;
  60. IdMessage := TIdMessage.Create(nil);
  61. end;
  62. destructor TIdMessageItem.Destroy;
  63. begin
  64. IdMessage.Free;
  65. inherited;
  66. end;
  67. function TIdMessageCollection.GetIdMessage(index: Integer): TIdMessage;
  68. begin
  69. Result := TIdMessageItem(Items[index]).IdMessage;
  70. end;
  71. procedure TIdMessageCollection.SetIdMessage(index: Integer;
  72. const Value: TIdMessage);
  73. begin
  74. //I think it should be freed before the new value is assigned or else the
  75. //pointer will be lost.
  76. TIdMessageItem(Items[index]).IdMessage.Free;
  77. TIdMessageItem(Items[index]).IdMessage := Value;
  78. end;
  79. end.