Gregory
-
Modifié le 10 févr. 2018 à 18:51
XeGregory51
Messages postés4Date d'inscriptionsamedi 10 février 2018StatutMembreDernière intervention27 juillet 2018
-
11 févr. 2018 à 06:35
Bonjour,
Comment peut on ignorer les erreurs d'un TClientdataset lors d'une mauvaise saisie ?
J'utilise un formulaire dynamique pour la saisie des données.
procedure TForm1.OnAddRecordClick(Sender: TObject);
var
I: Integer;
MyForm: TForm;
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;
Font.Size := 10;
Font.Name := 'Segoe UI';
Position := poMainFormCenter;
Width := 500;
Height := Width;
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, ftAutoInc:
begin
with TDBEdit.Create(MyForm) do
begin
Parent := ScrollBox;
Align := alTop;
AlignWithMargins := True;
Hint := MyGrid.Columns[I].Title.Caption;
ShowHint := True;
DataSource := F_MyXml.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 := F_MyXml.DataSource;
DataField := MyGrid.Columns[I].Title.Caption;
end;
end;
end;
end;
MyForm.ShowModal;
MyDataSet.Edit;
try
MyDataSet.Post;
except
ShowMessage('Erreur !');
end;
MyForm.Free;
end;
XeGregory51
Messages postés4Date d'inscriptionsamedi 10 février 2018StatutMembreDernière intervention27 juillet 2018 Modifié le 10 févr. 2018 à 19:44
J'ai ajouter un TApplicationEvents
procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
begin
E.Message := 'Type de données incorrect !';
ShowMessage(E.Message);
end;
Quand pensez vous ?
Merci ;)
XeGregory51
Messages postés4Date d'inscriptionsamedi 10 février 2018StatutMembreDernière intervention27 juillet 2018 11 févr. 2018 à 06:35
J'ai trouvé aussi cette solution la, avec le (ApplicationEvents OnException) pour ignorer toute les erreurs de la class "EDatabaseError"
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.
XeGregory51
Messages postés4Date d'inscriptionsamedi 10 février 2018StatutMembreDernière intervention27 juillet 2018 11 févr. 2018 à 06:19
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, ...) ?
11 févr. 2018 à 06:35
mais bon, il y a surement une solution plus adaptée.