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

Bases de données Delphi Discussion :

Ignorer les erreurs d'un TClientdataset


Sujet :

Bases de données Delphi

  1. #1
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    260
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 260
    Points : 171
    Points
    171
    Par défaut Ignorer les erreurs d'un TClientdataset
    Bonjour,

    Comment peut on ignorer les erreurs d'un TClientdataset lors d'une mauvaise saisie ?

    Exemple avec un TDBEdit :

    Nom : Capture.PNG
Affichages : 225
Taille : 11,4 Ko

    Merci
    Vous ne pouvez pas faire confiance à un code que vous n'avez pas totalement rédigé vous-même.

  2. #2
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    260
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 260
    Points : 171
    Points
    171
    Par défaut TApplicationEvents OnException
    J'ai ajouter un TApplicationEvents

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
    begin
      E.Message := 'Type de données incorrect !';
      ShowMessage(E.Message);
    end;
    Quand pensez vous ?

    Merci
    Vous ne pouvez pas faire confiance à un code que vous n'avez pas totalement rédigé vous-même.

  3. #3
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    260
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 260
    Points : 171
    Points
    171
    Par défaut Autre méthode
    J'ai chercher une autre méthode que le (ApplicationEvents OnException) pour intercepter les messages du TClientDataSet, mais en vain je n'arrive pas a prendre la main sur les exceptions.

    Le problème du (ApplicationEvents OnException) c'est qu'il traite l'intégralité des exceptions de l'application, c'est pas mon but.

    La question que je me pose, est ce que c'est vraiment le TClientDataSet qui génère les erreurs de saisie (TDBEdit, ...) ?

    Avez vous une petite idée ?

    Merci.
    Vous ne pouvez pas faire confiance à un code que vous n'avez pas totalement rédigé vous-même.

  4. #4
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    260
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 260
    Points : 171
    Points
    171
    Par défaut E.ClassName EDatabaseError
    J'ai trouvé aussi cette solution la, avec le (ApplicationEvents OnException) pour afficher les erreurs de la class "EDatabaseError"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
    begin
    if E.ClassName = 'EDatabaseError' then
       begin
        ShowMessage(E.Message);
       end;
    end;
    mais bon, il y a surement une solution plus adaptée.

    Nom : Capture.PNG
Affichages : 242
Taille : 20,7 Ko

    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
    var MyForm: TForm
     
    procedure TForm1.EDatabaseErrorException(Sender: TObject; E: Exception);
    begin
      if (E.ClassName = 'EDatabaseError') and (MyForm.Showing) then
      begin
        ShowMessage(E.Message);
      end;
    end;
     
    procedure TForm1.OnAddRecordClick(Sender: TObject);
    var
      I, MAction: Integer;
      ScrollBox: TScrollBox;
    begin
      if not MyDataSet.Active then
        Exit;
     
      MyForm := TForm.Create(nil);
      with MyForm do
      begin
        Caption := 'Ajouter un enregistrement';
        BorderIcons := [biSystemMenu];
        BorderStyle := bsSingle;
        CustomHint := BalloonHint;
        Font.Size := 10;
        Font.Name := 'Segoe UI';
        Position := poMainFormCenter;
        Width := 600;
        Height := 500;
      end;
     
      ScrollBox := TScrollBox.Create(MyForm);
      with ScrollBox do
      begin
        Parent := MyForm;
        Align := alClient;
        BorderStyle := bsNone;
        VertScrollBar.Tracking := True;
      end;
     
      for I := 0 to MyGrid.Columns.Count - 1 do
      begin
        case MyGrid.Columns[I].Field.DataType of
          ftString, ftCurrency, ftDateTime, ftInteger, ftfloat, ftBoolean:
            begin
              with TDBEdit.Create(MyForm) do
              begin
                Parent := ScrollBox;
                Align := alTop;
                AlignWithMargins := True;
                Hint := MyGrid.Columns[I].Title.Caption;
                ShowHint := True;
                DataSource := Form1.DataSource;
                DataField := MyGrid.Columns[I].Title.Caption;
              end;
            end;
     
          ftMemo:
            begin
              with TDBMemo.Create(MyForm) do
              begin
                Parent := ScrollBox;
                Align := alTop;
                AlignWithMargins := True;
                Height := 150;
                Hint := MyGrid.Columns[I].Title.Caption;
                ShowHint := True;
                ScrollBars := ssBoth;
                DataSource := Form1.DataSource;
                DataField := MyGrid.Columns[I].Title.Caption;
              end;
            end;
        end;
      end;
      MyDataSet.Last;
      MyDataSet.Insert;
      MyForm.ShowModal;
     
      MAction := MessageDlg('Ajouter l''enregistrement ?', mtCustom,
        [mbYes, mbNo], 0);
     
      case MAction of
        mrYes:
          begin
            try
              MyDataSet.Post;
            except
              MyDataSet.Cancel;
              ShowMessage('Une erreur est survenue lors de l''enregistrement !');
            end;
          end;
        mrNo:
          begin
            MyDataSet.Cancel;
            MyDataSet.First;
          end;
      end;
     
      MyForm.Free;
    end;
    Vous ne pouvez pas faire confiance à un code que vous n'avez pas totalement rédigé vous-même.

  5. #5
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 459
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 459
    Points : 24 873
    Points
    24 873
    Par défaut
    Et as-tu essayé TField.OnSetText ?
    Tiens, la même question d'un autre Grégory : Traiter les erreurs ClientDataSet (Xml) .
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  6. #6
    Membre habitué Avatar de XeGregory
    Homme Profil pro
    Passionné par la programmation
    Inscrit en
    Janvier 2017
    Messages
    260
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Passionné par la programmation
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2017
    Messages : 260
    Points : 171
    Points
    171
    Par défaut ClientDataSet OnSetText
    Citation Envoyé par ShaiLeTroll Voir le message
    Et as-tu essayé TField.OnSetText ?
    Tiens, la même question d'un autre Grégory : Traiter les erreurs ClientDataSet (Xml) .
    Bonjour ShaiLeTroll,

    Je viens de tester l’événement "OnSetText", ça a l'air de fonctionner :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    { MyMessage }
    procedure MyMessage(Title, StrMessage: String);
    begin
      with CreateMessageDialog(StrMessage, mtCustom, [mbOk], mbOk) do
      begin
        Caption := Title;
        try
          ShowModal;
        finally
          Free;
        end;
      end;
    end;
    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
    { SetText }
    procedure SetText(Sender: TField; const Text: String);
    var
      StrTypeData: String;
    begin
      try
        Sender.Value := Text;
      except
        case Sender.DataType of
          ftBoolean:
            StrTypeData := 'Boolean';
          ftCurrency:
            StrTypeData := 'Currency';
          ftInteger:
            StrTypeData := 'Integer';
          ftFloat:
            StrTypeData := 'Float';
          ftDate:
            StrTypeData := 'Date';
          ftTime:
            StrTypeData := 'Time';
        end;
         MyMessage('Err : ' + StrTypeData, 'Type de données incorrect !');
      end;
    end;
    MyDataSet.Fields[IFiels].OnSetText := OnSetText;
    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
    { CreateMyForm }
    procedure CreateMyForm(MyAction: Integer);
    var
      IFiels, ITop, MyBtAction: Integer;
      ScrollBox: TScrollBox;
    begin
      MyForm := TForm.Create(nil);
      with MyForm do
      begin
        case MyAction of
          0: { AddRecord }
            MyForm.Caption := 'Ajouter un enregistrement';
     
          1: { EditRecord }
            MyForm.Caption := 'Modifier l''enregistrement';
        end;
     
        BorderIcons := [biSystemMenu];
        BorderStyle := bsSingle;
        Font.Size := 10;
        Font.Name := 'Segoe UI';
        Position := poMainFormCenter;
        Width := 600;
        Height := 500;
      end;
     
      ScrollBox := TScrollBox.Create(MyForm);
      with ScrollBox do
      begin
        Parent := MyForm;
        Align := alClient;
        AlignWithMargins := True;
        BorderStyle := bsNone;
        VertScrollBar.Tracking := True;
      end;
     
      ITop := 8;
      for IFiels := 0 to MyGrid.Columns.Count - 1 do
      begin
        MyDataSet.Fields[IFiels].OnSetText := OnSetText;
     
        with TLabel.Create(MyForm) do
        begin
          Parent := ScrollBox;
          Top := ITop;
          Left := 8;
          Anchors := [akLeft, akTop, akRight];
          Caption := '[' + MyGrid.Columns.Items[IFiels].Title.Caption + ']';
          Width := ScrollBox.ClientWidth - 16;
          Inc(ITop, Height + 4);
        end;
     
        case MyGrid.Columns[IFiels].Field.DataType of
          ftAutoInc, ftString, ftCurrency, ftDateTime, ftInteger, ftFloat,
            ftBoolean, ftDate, ftTime:
            begin
              with TDBEdit.Create(MyForm) do
              begin
                Parent := ScrollBox;
                Top := ITop;
                Left := 8;
                Anchors := [akLeft, akTop, akRight];
                Width := ScrollBox.ClientWidth - 16;
                DataSource := F_MyXml.DataSource;
                DataField := MyGrid.Columns.Items[IFiels].Title.Caption;
                Inc(ITop, Height + 4);
     
                if MyGrid.Columns[IFiels].Field.DataType = ftAutoInc then
                begin
                  Cursor := crNo;
                  ReadOnly := True;
                end;
              end;
            end;
     
          ftMemo:
            begin
              with TDBMemo.Create(MyForm) do
              begin
                Parent := ScrollBox;
                Top := ITop;
                Left := 8;
                Anchors := [akLeft, akTop, akRight];
                Width := ScrollBox.ClientWidth - 16;
                Height := 150;
                ScrollBars := ssBoth;
                DataSource := F_MyXml.DataSource;
                DataField := MyGrid.Columns.Items[IFiels].Title.Caption;
                Inc(ITop, Height + 4);
              end;
            end;
        end;
      end;
     
      MyForm.ShowModal;
     
      case MyAction of
        0: { AddRecord }
          MyBtAction := MessageDlg('Ajouter l''enregistrement ?', mtCustom,
            [mbYes, mbNo], 0);
     
        1: { EditRecord }
          MyBtAction := MessageDlg('Modifier l''enregistrement ?', mtCustom,
            [mbYes, mbNo], 0);
      end;
     
      case MyBtAction of
        mrYes: { Oui }
          begin
            try
              MyDataSet.Post;
              MyDataSet.MergeChangeLog;
            except
              MyDataSet.Cancel;
              ShowMessage('Une erreur est survenue lors de l''enregistrement !');
            end;
          end;
     
        mrNo: { Non }
          MyDataSet.Cancel;
      end;
     
      FreeAndNil(MyForm);
    end;
    Merci ShaiLeTroll
    Vous ne pouvez pas faire confiance à un code que vous n'avez pas totalement rédigé vous-même.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Visual Studio 2010 ignore les erreurs
    Par asmduty dans le forum Visual Studio
    Réponses: 3
    Dernier message: 28/03/2011, 10h43
  2. Ignorer les Erreurs émit par le système
    Par yann87 dans le forum Langage
    Réponses: 2
    Dernier message: 07/07/2009, 12h50
  3. ignorer les erreurs de certificas SSL pour DirectoryServices..
    Par olivier.schmitt2 dans le forum VB.NET
    Réponses: 1
    Dernier message: 06/02/2008, 14h08
  4. Réponses: 3
    Dernier message: 21/06/2007, 12h53
  5. [pgAdminIII] Comment ignorer les erreurs de script
    Par Escandil dans le forum PostgreSQL
    Réponses: 6
    Dernier message: 22/07/2005, 12h03

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