I wrote a few TAction base classes (like TDataSetAdd or TDataSetReOpen) and it works like a charm. Now I tried to write an action to process the transaction, but for some reason it behaves somewhat unexpectedly. The "HandlesTarget" function never shows my transactional component as an object at all, although it is in form? What am I missing? Thanks in advance.
TFDTransactionAction = class(TAction)
private
FTransaction: TFDTransaction;
procedure SetTransaction(Value: TFDTransaction);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
function HandlesTarget(Target: TObject): Boolean; override;
property Transaction: TFDTransaction read FTransaction write SetTransaction;
end;
TFDCommitAction = class(TFDTransactionAction)
public
procedure ExecuteTarget(Target: TObject); override;
procedure UpdateTarget(Target: TObject); override;
published
property Transaction;
end;
{ TFDTransactionAction }
function TFDTransactionAction.HandlesTarget(Target: TObject): Boolean;
begin
Result := ((Transaction <> nil) or
(Transaction = nil) and (Target is TFDTransaction));
end;
procedure TFDTransactionAction.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = Transaction) then
Transaction := nil;
end;
procedure TFDTransactionAction.SetTransaction(Value: TFDTransaction);
begin
if FTransaction <> Value then
begin
FTransaction := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
end;
{ TFDCommitAction }
procedure TFDCommitAction.ExecuteTarget(Target: TObject);
begin
Transaction.Commit
end;
procedure TFDCommitAction.UpdateTarget(Target: TObject);
begin
Enabled := TFDTransaction(Target).Active
end;
end.
source
share