IdMessageCollection.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.2 2004.10.26 2:19:58 PM czhower
  18. Resolved alias conflict.
  19. Rev 1.1 14/07/2004 21:37:26 CCostelloe
  20. Changed Get/SetMessage to Get/SetIdMessage to avoid conflict under C++ with
  21. Windows' GetMessage
  22. Rev 1.0 11/13/2002 07:57:28 AM JPMugaas
  23. 2000-APR-14 Peter Mee: Converted to Indy.
  24. 2001-MAY-03 Idan Cohen: Added Create and Destroy of TIdMessage.
  25. }
  26. unit IdMessageCollection;
  27. {
  28. TIdMessageCollection: Contains a collection of IdMessages.
  29. Originally by Peter Mee.
  30. }
  31. interface
  32. {$i IdCompilerDefines.inc}
  33. uses
  34. Classes,
  35. IdMessage;
  36. type
  37. TIdMessageItems = class of TIdMessageItem;
  38. TIdMessageItem = class(TCollectionItem)
  39. protected
  40. FAttempt: Integer;
  41. FMsg: TIdMessage;
  42. FQueued: Boolean;
  43. public
  44. constructor Create(Collection: TCollection); override;
  45. destructor Destroy; override;
  46. //
  47. property Attempt: Integer read FAttempt write FAttempt;
  48. property Msg: TIdMessage read FMsg;
  49. property Queued: Boolean read FQueued write FQueued;
  50. end;
  51. TIdMessageCollection = class(TCollection)
  52. private
  53. function GetIdMessage(index: Integer): TIdMessage;
  54. procedure SetIdMessage(index: Integer; const Value: TIdMessage);
  55. public
  56. constructor Create; reintroduce;
  57. function Add: TIdMessageItem;
  58. property Messages[index: Integer]: TIdMessage read GetIdMessage write SetIdMessage; Default;
  59. end;
  60. implementation
  61. uses
  62. IdGlobal, SysUtils;
  63. { TIdMessageItem }
  64. constructor TIdMessageItem.Create(Collection: TCollection);
  65. begin
  66. inherited Create(Collection);
  67. FMsg := TIdMessage.Create(nil);
  68. end;
  69. destructor TIdMessageItem.Destroy;
  70. begin
  71. FreeAndNil(FMsg);
  72. inherited Destroy;
  73. end;
  74. { TIdMessageCollection }
  75. constructor TIdMessageCollection.Create;
  76. begin
  77. inherited Create(TIdMessageItem);
  78. end;
  79. function TIdMessageCollection.Add;
  80. begin
  81. Result := TIdMessageItem(inherited Add);
  82. end;
  83. function TIdMessageCollection.GetIdMessage(index: Integer): TIdMessage;
  84. begin
  85. Result := TIdMessageItem(Items[index]).Msg;
  86. end;
  87. procedure TIdMessageCollection.SetIdMessage(index: Integer; const Value: TIdMessage);
  88. begin
  89. //I think it should be freed before the new value is assigned or else the
  90. //pointer will be lost.
  91. // RLebeau 6/3/2010: this is taking ownership of the input TIdMessage
  92. // pointer! We should probably be calling Assign() instead, and let
  93. // the caller manage its TIdMessage object separately. Or else make
  94. // the Messages[] property read-only instead...
  95. TIdMessageItem(Items[index]).FMsg.Free;
  96. TIdMessageItem(Items[index]).FMsg := Value;
  97. end;
  98. end.