ProjGatherProperties.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. unit ProjGatherProperties;
  2. interface
  3. uses
  4. Classes, ZhAPI;
  5. type
  6. TProjGatherProperty = class
  7. private
  8. FName: string;
  9. FValue: string;
  10. public
  11. constructor Create(const AName: string);
  12. destructor Destroy; override;
  13. property Name: string read FName write FName;
  14. property Value: string read FValue write FValue;
  15. end;
  16. TProjGatherProperties = class
  17. private
  18. FList: TList;
  19. function FindProjGatherProperty(const AName: string): TProjGatherProperty;
  20. function AddProjGatherProperty(const AName: string): TProjGatherProperty;
  21. function GetCount: Integer;
  22. function GetPgPropperty(AIndex: Integer): TProjGatherProperty;
  23. public
  24. constructor Create;
  25. destructor Destroy; override;
  26. function GetProjGatherProperty(const AName: string): TProjGatherProperty;
  27. property Count: Integer read GetCount;
  28. property PgProperty[AIndex: Integer]: TProjGatherProperty read GetPgPropperty;
  29. end;
  30. implementation
  31. uses SysUtils;
  32. { TProjGatherProperty }
  33. constructor TProjGatherProperty.Create(const AName: string);
  34. begin
  35. FName := AName;
  36. end;
  37. destructor TProjGatherProperty.Destroy;
  38. begin
  39. inherited;
  40. end;
  41. { TProjGatherProperties }
  42. function TProjGatherProperties.AddProjGatherProperty(
  43. const AName: string): TProjGatherProperty;
  44. begin
  45. Result := TProjGatherProperty.Create(AName);
  46. FList.Add(Result);
  47. end;
  48. constructor TProjGatherProperties.Create;
  49. begin
  50. FList := TList.Create;
  51. end;
  52. destructor TProjGatherProperties.Destroy;
  53. begin
  54. ClearObjects(FList);
  55. FList.Free;
  56. inherited;
  57. end;
  58. function TProjGatherProperties.FindProjGatherProperty(
  59. const AName: string): TProjGatherProperty;
  60. var
  61. i: Integer;
  62. vProperty: TProjGatherProperty;
  63. begin
  64. Result := nil;
  65. for i := 0 to Count - 1 do
  66. begin
  67. vProperty := PgProperty[i];
  68. if vProperty.Name = AName then
  69. begin
  70. Result := vProperty;
  71. Break;
  72. end;
  73. end;
  74. end;
  75. function TProjGatherProperties.GetCount: Integer;
  76. begin
  77. Result := FList.Count;
  78. end;
  79. function TProjGatherProperties.GetPgPropperty(
  80. AIndex: Integer): TProjGatherProperty;
  81. begin
  82. Result := TProjGatherProperty(FList.Items[AIndex]);
  83. end;
  84. function TProjGatherProperties.GetProjGatherProperty(
  85. const AName: string): TProjGatherProperty;
  86. begin
  87. Result := FindProjGatherProperty(AName);
  88. if not Assigned(Result) then
  89. Result := AddProjGatherProperty(AName);
  90. end;
  91. end.