Skip to content

Commit

Permalink
OCLVariables now subscribe to BoldOcl. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 7, 2024
1 parent 7d7dba5 commit 178ad6a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Source/BoldElements.pas
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ TBoldExternalVariable = class(TBoldMemoryManagedObject)
private
fName: String;
fEvaluator: TBoldEvaluator;
fSubscriber: TBoldPassthroughSubscriber;
procedure Receive(Originator: TObject; OriginalEvent: TBoldEvent; RequestedEvent: TBoldRequestedEvent);
function GetSubscriber: TBoldPassthroughSubscriber;
procedure SetEvaluator(const Value: TBoldEvaluator);
property Subscriber: TBoldPassthroughSubscriber read GetSubscriber;
protected
function GetValue: TBoldElement; virtual; abstract;
function GetValueType: TBoldElementTypeInfo; virtual; abstract;
Expand All @@ -174,7 +179,7 @@ TBoldExternalVariable = class(TBoldMemoryManagedObject)
property Value: TBoldElement read GetValue;
property Name: String read fName;
property ValueType: TBoldElementTypeInfo read GetValueType;
property Evaluator: TBoldEvaluator read fEvaluator write fEvaluator;
property Evaluator: TBoldEvaluator read fEvaluator write SetEvaluator;
end;

TBoldExternalVariableListTraverser = class(TBoldArrayTraverser)
Expand Down Expand Up @@ -209,7 +214,7 @@ TBoldExternalVariableList = class(TBoldObjectArray)
end;

{---TBoldEvaluator---}
TBoldEvaluator = class(TBoldMemoryManagedObject)
TBoldEvaluator = class(TBoldSubscribableObject)
protected
function GetVariableCount: integer; virtual; abstract;
function GetVariable(index: integer): TBoldIndirectElement; virtual; abstract;
Expand Down Expand Up @@ -964,18 +969,43 @@ procedure TBoldElementTypeInfo.SetValueType(NewValue: TBoldValueTypeSet);
constructor TBoldExternalVariable.Create(AEvaluator: TBoldEvaluator; const AName: String);
begin
inherited Create;
fEvaluator := AEvaluator;
Evaluator := AEvaluator;
fName := AName;
end;

destructor TBoldExternalVariable.Destroy;
begin
fSubscriber.Free;
if Assigned(fEvaluator) then
fEvaluator.UndefineVariable(self);
fEvaluator := nil;
inherited;
end;

function TBoldExternalVariable.GetSubscriber: TBoldPassthroughSubscriber;
begin
if not Assigned(fSubscriber) then
fSubscriber := TBoldPassthroughSubscriber.Create(Receive);
result := fSubscriber;
end;

procedure TBoldExternalVariable.Receive(Originator: TObject;
OriginalEvent: TBoldEvent; RequestedEvent: TBoldRequestedEvent);
begin
fEvaluator := nil;
end;

procedure TBoldExternalVariable.SetEvaluator(const Value: TBoldEvaluator);
begin
if fEvaluator <> Value then
begin
fEvaluator := Value;
Subscriber.CancelAllSubscriptions;
if Assigned(fEvaluator) then
fEvaluator.AddSmallSubscription(Subscriber, [beDestroying]);
end;
end;

{ TBoldExternalOclVariableList }

procedure TBoldExternalVariableList.Add(Variable: TBoldExternalVariable);
Expand Down
1 change: 1 addition & 0 deletions Source/BoldOcl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ constructor TBoldOcl.Create(ASystemTypeInfo: TBoldSystemTypeInfo; ABoldSystem: T

destructor TBoldOcl.Destroy;
begin
SendEvent(beDestroying);
FreeAndNil(fOclDictionary);
FreeAndNil(fSymbolTable);
FreeAndNil(fGlobalEnv);
Expand Down

0 comments on commit 178ad6a

Please sign in to comment.