Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Classes;
- type
- TPriceKey = class
- public
- PriceTermKeyObj: TObject;
- PriceTermList: TList;
- constructor Create;
- destructor Destroy; override;
- end;
- TPriceKeyList = class(TList)
- private
- function Get(Index: Integer): TPriceKey;
- public
- destructor Destroy; override;
- procedure AddNew(APriceTermKey: TObject; APriceTermList: TList);
- property Items[Index: Integer]: TPriceKey read Get; default;
- end;
- TTest = class
- public
- class procedure PublishKeys(AValidFrom: TDate; AValidTo: TDate);
- end;
- implementation
- uses
- VCL.Controls,
- Vcl.Dialogs,
- SysUtils;
- function TPriceKeyList.Get(Index: Integer): TPriceKey;
- begin
- Result := TPriceKey(inherited Get(Index));
- end;
- constructor TPriceKey.Create;
- begin
- PriceTermList := TList.Create;
- end;
- destructor TPriceKey.Destroy;
- begin
- FreeAndNil(PriceTermList);
- end;
- destructor TPriceKeyList.Destroy;
- var
- i: Integer;
- begin
- for i := Count - 1 downto 0 do
- FreeAndNil(Items[i]);
- inherited;
- end;
- procedure TPriceKeyList.AddNew(APriceTermKey: TObject; APriceTermList: TList);
- var
- oKey: TPriceKey;
- begin
- oKey := TPriceKey.Create;
- oKey.PriceTermKeyObj := APriceTermKey;
- Add(oKey);
- end;
- class procedure TTest.PublishKeys(AValidFrom: TDate; AValidTo: TDate);
- var
- oPriceKey: TPriceKey;
- oPriceTermList: TList;
- oAllTargetPriceTerms: TList;
- oPriceKeyRevision: TObject;
- oPriceRevision, oNewPriceRevision: TObject;
- oCreatedRevisions: TList;
- oAgreementList: TList;
- ResultCount: Integer;
- iConfirmResult: Integer;
- bYesToAll, bAbort: Boolean;
- sOrgname: string;
- begin
- if AValidFrom >= AValidTo then
- begin
- WriteLn(Format('Valid from %s must be before Valid to %s', [DateToStr(AValidFrom), DateToStr(AValidTo)]));
- Exit;
- end;
- ResultCount := 0;
- oPriceTermList := TList.Create;
- oAllTargetPriceTerms := TList.Create;
- oCreatedRevisions := TList.Create;
- try
- for oPriceKey in oAllTargetPriceTerms do
- begin
- bYesToAll := False;
- bAbort := False;
- for var oAgreement in oAgreementList do
- begin
- if bAbort then
- begin
- Break;
- end;
- if Assigned(oPriceRevision) then
- begin
- oNewPriceRevision := oPriceRevision; // Default value
- if oCreatedRevisions.IndexOf(oPriceRevision) > 0 then
- begin
- if not bYesToAll then
- begin
- case iConfirmResult of
- mrYesToAll: bYesToAll := True;
- mrNo: continue;
- mrAbort:
- begin
- bAbort := True;
- break;
- end;
- end;
- end;
- end;
- for var oPriceTerm in oCreatedRevisions do
- begin
- Inc(ResultCount);
- end;
- end;
- end;
- end;
- finally
- FreeAndNil(oPriceTermList);
- FreeAndNil(oAllTargetPriceTerms);
- FreeAndNil(oCreatedRevisions);
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement