Announcement

Collapse
No announcement yet.

Ereignis zeitweise abschalten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ereignis zeitweise abschalten

    Hallo,

    ich würde für gewisse Situationen gerne das Tabelle - BEFOREPOST Ereignis ausschalten. Wie kann ich dies zur Laufzeit einmal deaktivieren und später nach Wunsch wieder aktivieren?

    Heiko

  • #2
    Hallo Heiko,<BR><BR>
    das Ereignis wird erst mal ausgelöst. Du kannst nur beeinflusse, ob deine Methode dann ausgeführt wird oder nicht. Da gibt es 2 Ansätze.<BR>
    1. Variable -> BeforePostEventEnabled : Boolean;<BR>
    und in der Methode als erste Zeile:<PRE>
    if not BeforePostEventEnabled then
    Exit;</PRE>
    2. Propertie BeforePostEventEnabled mit Write Methode SetBeforePostEventEnabled;
    <PRE>
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, DB, DBTables;<BR>
    type
    TForm1 = class(TForm)
    MyTable: TTable;
    procedure doBeforePost(DataSet: TDataSet);
    private
    FBeforePostEventEnabled: Boolean;
    procedure SetBeforePostEventEnabled(const Value: Boolean);
    { Private-Deklarationen }
    public
    property BeforePostEventEnabled: Boolean read FBeforePostEventEnabled write
    SetBeforePostEventEnabled;
    { Public-Deklarationen }
    end;<BR>
    var
    Form1: TForm1;<BR>
    implementation<BR>
    {$R *.dfm}<BR>
    procedure TForm1.SetBeforePostEventEnabled(const Value: Boolean);
    begin
    if FBeforePostEventEnabled <> Value then
    begin
    FBeforePostEventEnabled := Value;
    if FBeforePostEventEnabled then
    MyTable.BeforePost := doBeforePost
    else
    MyTable.BeforePost := nil;
    end;
    end;<BR>
    procedure TForm1.doBeforePost(DataSet: TDataSet);
    begin
    // diese Zeile nur für Variante 1
    if not BeforePostEventEnabled then
    Exit;
    // mach was
    end;<BR>
    end.</PRE>
    So kannst du mit:<BR>
    BeforePostEventEnabled := False;<BR>
    deine Methode ab- und anschalten.<BR><BR>
    Fran

    Comment

    Working...
    X