IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

la Procedure Notification


Sujet :

Composants VCL Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de saidus
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48

    Informations forums :
    Inscription : Octobre 2004
    Messages : 166
    Par défaut la Procedure Notification
    Bonjour !!
    J'ai un petit probleme
    j'ai creer 2 classes, une qui descent de TPersistent(TOptionQuery) et l'autre de TMyQuery(TMyBaseQuery)
    j'ai declarer une instance de la premiere dans la deuxieme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
     type 
        TOptionQuery = class(TPersistent)
         .....
        published 
         ..... 
           property CxEditor : TCxDBTextEditor read CxEditor write SetCxEditor ;
        end;
     
        TMyBaseQuery= class(TMyQuery)
        ....
        protected
           procedure Notification(AComponent: TComponent; Operation: TOperation); override;
        public
           constructor Create(AOwner: TComponent);override;
           Destructor Destroy; override;
           procedure Notification()
        published 
           property QOption: TOptionQuery read FQOption write FQOption;
        end;
    // cxEditor est un control de type TDBEdit
    ........
     
    procedure TMyBaseQuery.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      inherited Notification(AComponent,Operation);
        if (Operation=opRemove) and (AComponent=QOption.CxEditor) then
         QOption.CxEditor := nil;
    end;
    maintenant !! quand je pose le composant TmybaseQuery sur la forme et je relie sa properiete QOption.CxEditor a un composant de type TCxDBEditor (cxEdit1 )tout marche bien !!! mais le probleme survient lorsque je supprime ce dernier(cxEdit1),l'IDE delphi genere alors des messages d'erruer ...
    et pourtant j'ai reecrit la procedure Notification .
    que dois-je faire ...
    merci pour votre aide

  2. #2
    Membre confirmé Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Par défaut


    Peut être faut il que tu supprime QOptions.Cxeditor avec FreeAndNil:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    procedure TMyBaseQuery.Notification(AComponent: TComponent; Operation: TOperation);
    begin
      inherited Notification(AComponent,Operation);
        if (Operation=opRemove) and (AComponent=QOption.CxEditor) then
         FreeAndNil(QOption.CxEditor);
    end;

  3. #3
    Expert confirmé

    Avatar de sjrd
    Homme Profil pro
    Directeur de projet
    Inscrit en
    Juin 2004
    Messages
    4 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Suisse

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2004
    Messages : 4 517
    Par défaut
    Tu as oublié de demander au composant CxEditor de t'envoyer une notification
    Pour cela, il faut appeler CxEditor.FreeNotification dans le SetCxEditor (et faire RemoveFreeNotification sur l'éventuelle ancienne valeur).
    Tout est expliqué en détails là :
    Sécuriser la destruction d'un composant référencé avec FreeNotification
    sjrd, ancien rédacteur/modérateur Delphi.
    Auteur de Scala.js, le compilateur de Scala vers JavaScript, et directeur technique du Scala Center à l'EPFL.
    Découvrez Mes tutoriels.

  4. #4
    Membre confirmé Avatar de saidus
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48

    Informations forums :
    Inscription : Octobre 2004
    Messages : 166
    Par défaut
    Bonjour Messieurs
    Voici le Code que j'ai ecris et qui est toujours bogue ..
    je ne sais pas ce qui m'echappe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
     
    type
      TBSClientQuery = class ;
     
      TBSClientOption = class (TPersistent)
      private
        FClient : TBSClientQuery;
        FEditor: TcxDBTextEdit;
        FRequiredField_1: TStringField;
        FRequiredField_2: TStringField;
        FAskbeforeDelete: Boolean;
        FDeleteMsg: string;
        procedure SetEditor(const Value: TcxDBTextEdit);
        procedure SetRequiredField_1(const Value: TStringField);
        procedure SetRequiredField_2(const Value: TStringField);
        procedure CtrlDelete;
        procedure CtrlEditor;
        procedure CtrlEmptyField;
      protected
      public
        constructor Create(Client : TBSClientQuery);
        destructor Destroy ; override;
      published
        property RequiredField_1: TStringField read FRequiredField_1 write SetRequiredField_1;
        property RequiredField_2: TStringField read FRequiredField_2 write SetRequiredField_2;
        property Editor: TcxDBTextEdit read FEditor write SetEditor ;
        property DeleteMsg: string read FDeleteMsg write FDeleteMsg;
        property AskbeforeDelete: Boolean read FAskbeforeDelete write FAskbeforeDelete;
     
      end;
    { ==================================================================================== }
    {  Exception Handler will intercept all exceptions in levels :                         }
    {  ------------------------                                                            }
    {   +   Before insert
        +   Before Post
        +   Before Edit
        +   Before Delete
        +   Before Cancel
        +   Before Refresh
    }
      TBSClientQuery = class(TBSDataSet)
      private
        FAfterCancel: TDataSetNotifyEvent;
        FAfterDelete: TDataSetNotifyEvent;
        FAfterEdit: TDataSetNotifyEvent;
        FAfterInsert: TDataSetNotifyEvent;
        FAfterPost: TDataSetNotifyEvent;
        FBeforeCancel: TDataSetNotifyEvent;
        FBeforeDelete: TDataSetNotifyEvent;
        FBeforeEdit: TDataSetNotifyEvent;
        FBeforeInsert: TDataSetNotifyEvent;
        FBeforePost: TDataSetNotifyEvent;
        FClientOption: TBSClientOption;
        OldException : TExceptionEvent;
      protected
        procedure DoAfterCancel; override;
        procedure DoAfterDelete; override;
        procedure DoAfterEdit; override;
        procedure DoAfterInsert; override;
        procedure DoAfterPost; override;
        procedure DoBeforeCancel; override;
        procedure DoBeforeDelete; override;
        procedure DoBeforeEdit; override;
        procedure DoBeforeInsert; override;
        procedure DoBeforePost; override;
        procedure BSFireException(Sender:TObject;E:Exception);
        procedure BSInstallExecption;
        procedure BSUninstallException;
     
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
     
      public
        constructor Create(AOwner: TComponent); override;
        destructor  Destroy; override;
      published
        property BeforeInsert: TDataSetNotifyEvent read FBeforeInsert write FBeforeInsert;
        property AfterInsert: TDataSetNotifyEvent read FAfterInsert write FAfterInsert;
        property BeforeEdit: TDataSetNotifyEvent read FBeforeEdit write FBeforeEdit;
        property AfterEdit: TDataSetNotifyEvent read FAfterEdit write FAfterEdit;
        property BeforePost: TDataSetNotifyEvent read FBeforePost write FBeforePost;
        property AfterPost: TDataSetNotifyEvent read FAfterPost write FAfterPost;
        property BeforeCancel: TDataSetNotifyEvent read FBeforeCancel write FBeforeCancel;
        property AfterCancel: TDataSetNotifyEvent read FAfterCancel write FAfterCancel;
        property BeforeDelete: TDataSetNotifyEvent read FBeforeDelete write FBeforeDelete;
        property AfterDelete: TDataSetNotifyEvent read FAfterDelete write FAfterDelete;
     
        property ClientOption: TBSClientOption read FClientOption write FClientOption;
      end;
     
     
    implementation
     
    constructor TBSClientQuery.Create(AOwner: TComponent);
    begin
      inherited;
      FClientOption := TBSClientOption.Create(Self);
    end;
     
    { ------------------------------------------------------- }
    {}
    { ------------------------------------------------------- }
    destructor TBSClientQuery.Destroy;
    begin
      FreeAndNil(FClientOption);
      inherited;
    end;
     
    { ------------------------------------------------------- }
    {}
    { ------------------------------------------------------- }
    procedure TBSClientQuery.Notification(AComponent: TComponent;
      Operation: TOperation);
    begin
      inherited Notification(AComponent,Operation);
      if (Operation = opRemove) and (AComponent=FClientOption.FEditor)          then
           FClientOption.FEditor          := nil;
      if (Operation = opRemove) and (AComponent=FClientOption.FRequiredField_1) then
           FClientOption.FRequiredField_1 := nil;
      if (Operation = opRemove) and (AComponent=FClientOption.FRequiredField_2) then
           FClientOption.FRequiredField_2 := nil;   
    end;
     
    .........
     
    procedure TBSClientOption.SetEditor(const Value: TcxDBTextEdit);
    begin
    //  FEditor := Value;
    //  CtrlEditor;
    //{
    //if FEditor<>nil then
    //     FEditor.FreeNotification(FClient);
      if Assigned(FEditor) and (not (csDestroying in FEditor.ComponentState)) then
          FEditor.RemoveFreeNotification(FClient);
      FEditor := Value;
      if Assigned(FEditor) then
         FEditor.FreeNotification(FClient);
      CtrlEditor;
    //     }
    end;
     
    { ------------------------------------------------------- }
    {}
    { -------------------------------------------------------} 
    procedure TBSClientOption.SetRequiredField_1(const Value: TStringField);
    begin
    //  FRequiredField_1 := Value;
      if Assigned(FRequiredField_1) and (not (csDestroying in FRequiredField_1.ComponentState)) then
          FRequiredField_1.RemoveFreeNotification(FClient);
      FRequiredField_1 := Value;
      if Assigned(FRequiredField_1) then
         FRequiredField_1.FreeNotification(FClient);
    end;
     
    { ------------------------------------------------------- }
    {}
    { ------------------------------------------------------- }
    procedure TBSClientOption.SetRequiredField_2(const Value: TStringField);
    begin
    //  FRequiredField_2 := Value;
      if Assigned(FRequiredField_2) and (not (csDestroying in FRequiredField_2.ComponentState)) then
          FRequiredField_2.RemoveFreeNotification(FClient);
      FRequiredField_2 := Value;
      if Assigned(FRequiredField_2) then
         FRequiredField_2.FreeNotification(FClient);
    end;
     
     
    constructor TBSClientOption.Create(Client: TBSClientQuery);
    begin
      FClient := Client;
    end;
     
    destructor TBSClientOption.Destroy;
    begin
      FClient := nil;
      inherited;
    end;
    merci pour votre aide !!

  5. #5
    Expert confirmé

    Avatar de sjrd
    Homme Profil pro
    Directeur de projet
    Inscrit en
    Juin 2004
    Messages
    4 517
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Suisse

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2004
    Messages : 4 517
    Par défaut
    Euh non comme ça ça m'a l'air juste
    Peux-tu nous dire si l'exécution passe bien par les méthodes concernées (les SetXXX et la procédure Notification). Il suffit de mettre un ShowMessage dans chacune.
    sjrd, ancien rédacteur/modérateur Delphi.
    Auteur de Scala.js, le compilateur de Scala vers JavaScript, et directeur technique du Scala Center à l'EPFL.
    Découvrez Mes tutoriels.

  6. #6
    Membre confirmé Avatar de saidus
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48

    Informations forums :
    Inscription : Octobre 2004
    Messages : 166
    Par défaut
    j'utilise l'utilitaire Eurekalog et j'ai le resultat suivant (voir le fichier text)
    et quant je diagnostique l'erreur il me renvoie a la procedure de notification

  7. #7
    Membre Expert

    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 1 519
    Billets dans le blog
    1
    Par défaut
    Est-ce qu'il ne faudrait pas utiliser Self plutôt que FClient ? Parce que actuellement c'est FClient (le DataSet) qui reçoit les notifications alors que les affectations sont dans la propriété ClientOption qui appartient à FClient.

Discussions similaires

  1. Apropos des Transactions au sein d'un Stored Procedure
    Par Sarbacane dans le forum Connexion aux bases de données
    Réponses: 6
    Dernier message: 16/11/2004, 09h21
  2. [VB6] Interrompre toutes procédures
    Par lutin_vert dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 10/09/2002, 12h39
  3. Declaration Type ds une procedure
    Par Qwazerty dans le forum Langage
    Réponses: 6
    Dernier message: 28/08/2002, 10h09
  4. [TP]code asm dans une procedure
    Par M.Dlb dans le forum Turbo Pascal
    Réponses: 3
    Dernier message: 17/08/2002, 21h43
  5. Reprendre une procedure dans une autre ?
    Par Poisson Rouge dans le forum Langage
    Réponses: 3
    Dernier message: 17/07/2002, 23h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo