自定义Delphi动作类

时间:2015-02-03 12:19:54

标签: delphi firedac

我写了一些基本的TAction类(比如TDataSetAdd或TDataSetReOpen),它就像一个魅力。现在我尝试编写一个动作来处理事务的提交,但由于某种原因,它的行为有些出乎意料。 “HandlesTarget”函数从不将我的事务组件显示为对象,尽管它在表单上?我错过了什么?提前谢谢。

  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.

0 个答案:

没有答案