Advertisement
D98rolb

Example of wrong hint H2077 in Delphi 11.3

May 17th, 2024
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.06 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes;
  7.  
  8. type
  9.   TPriceKey = class
  10.   public
  11.     PriceTermKeyObj: TObject;
  12.     PriceTermList: TList;
  13.     constructor Create;
  14.     destructor Destroy; override;
  15.   end;
  16.  
  17.   TPriceKeyList = class(TList)
  18.   private
  19.     function Get(Index: Integer): TPriceKey;
  20.   public
  21.     destructor Destroy; override;
  22.     procedure AddNew(APriceTermKey: TObject; APriceTermList: TList);
  23.     property Items[Index: Integer]: TPriceKey read Get; default;
  24.   end;
  25.  
  26.   TTest = class
  27.   public
  28.     class procedure PublishKeys(AValidFrom: TDate; AValidTo: TDate);
  29.   end;
  30.  
  31. implementation
  32.  
  33. uses
  34.   VCL.Controls,
  35.   Vcl.Dialogs,
  36.   SysUtils;
  37.  
  38. function TPriceKeyList.Get(Index: Integer): TPriceKey;
  39. begin
  40.   Result := TPriceKey(inherited Get(Index));
  41. end;
  42.  
  43. constructor TPriceKey.Create;
  44. begin
  45.   PriceTermList := TList.Create;
  46. end;
  47.  
  48. destructor TPriceKey.Destroy;
  49. begin
  50.   FreeAndNil(PriceTermList);
  51. end;
  52.  
  53. destructor TPriceKeyList.Destroy;
  54. var
  55.   i: Integer;
  56. begin
  57.   for i := Count - 1 downto 0 do
  58.     FreeAndNil(Items[i]);
  59.   inherited;
  60. end;
  61.  
  62. procedure TPriceKeyList.AddNew(APriceTermKey: TObject; APriceTermList: TList);
  63. var
  64.   oKey: TPriceKey;
  65. begin
  66.   oKey := TPriceKey.Create;
  67.   oKey.PriceTermKeyObj := APriceTermKey;
  68.   Add(oKey);
  69. end;
  70.  
  71. class procedure TTest.PublishKeys(AValidFrom: TDate; AValidTo: TDate);
  72. var
  73.   oPriceKey: TPriceKey;
  74.   oPriceTermList: TList;
  75.   oAllTargetPriceTerms: TList;
  76.   oPriceKeyRevision: TObject;
  77.   oPriceRevision, oNewPriceRevision: TObject;
  78.   oCreatedRevisions: TList;
  79.   oAgreementList: TList;
  80.   ResultCount: Integer;
  81.   iConfirmResult: Integer;
  82.   bYesToAll, bAbort: Boolean;
  83.   sOrgname: string;
  84. begin
  85.   if AValidFrom >= AValidTo then
  86.   begin
  87.     WriteLn(Format('Valid from %s must be before Valid to %s', [DateToStr(AValidFrom), DateToStr(AValidTo)]));
  88.     Exit;
  89.   end;
  90.  
  91.   ResultCount := 0;
  92.   oPriceTermList := TList.Create;
  93.   oAllTargetPriceTerms := TList.Create;
  94.   oCreatedRevisions := TList.Create;
  95.   try
  96.     for oPriceKey in oAllTargetPriceTerms do
  97.     begin
  98.       bYesToAll := False;
  99.       bAbort := False;
  100.       for var oAgreement in oAgreementList do
  101.       begin
  102.         if bAbort then
  103.         begin
  104.           Break;
  105.         end;
  106.  
  107.         if Assigned(oPriceRevision) then
  108.         begin
  109.           oNewPriceRevision := oPriceRevision;    // Default value
  110.  
  111.           if oCreatedRevisions.IndexOf(oPriceRevision) > 0 then
  112.           begin
  113.             if not bYesToAll then
  114.             begin
  115.               case iConfirmResult of
  116.                 mrYesToAll: bYesToAll := True;
  117.                 mrNo:       continue;
  118.                 mrAbort:
  119.                 begin
  120.                   bAbort := True;
  121.                   break;
  122.                 end;
  123.               end;
  124.             end;
  125.           end;
  126.  
  127.  
  128.           for var oPriceTerm in oCreatedRevisions do
  129.           begin
  130.             Inc(ResultCount);
  131.           end;
  132.         end;
  133.       end;
  134.     end;
  135.   finally
  136.     FreeAndNil(oPriceTermList);
  137.     FreeAndNil(oAllTargetPriceTerms);
  138.     FreeAndNil(oCreatedRevisions);
  139.   end;
  140. end;
  141.  
  142. end.
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement