|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
||||
|
||||
Обработка исключений
Здрасте! В одной из тем приводили код по обработке дублирующейся записи в базе. Код ниже:
Код:
procedure TForm1.ADOTable1PostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); begin ShowMessage('Такое имя уже есть'); Action := daAbort; end; Как нужно доработать код для обработки конкретной ошибки, а то что то я не пойму как это делать? И как их между собой различать? Заранее спасиб. |
#2
|
||||
|
||||
Цитата:
Пишу программы за еду. __________________ |
#3
|
||||
|
||||
А можно пример привести? а то я уже ни чего не понимаю?)
|
#4
|
||||
|
||||
из файла справки:
Цитата:
Пишу программы за еду. __________________ |
#5
|
||||
|
||||
Дублирующаяся запись в базе - ошибка?
|
#6
|
||||
|
||||
Цитата:
Цитата:
Есть таблица: Код:
create table man(id integer not null constraint Name_1 primary key, FIO varchar(30) not null, holiday data not null, phone numeric(11,0) not null, pol varchar(1) not null constraint Name_2 check((pol = 'М') or (pol = 'Ж')), constraint Name_3 unique(FIO,holiday)); Код:
try except Потому что в EDatabaseError срабатывает для всех ограничений одинаково: Код:
on E:EDatabaseError do MessageDlg('Ошибка добавления!'+#13+E.Message,mtError,[mbOK],0); Это вообще возможно? |
#7
|
||||
|
||||
Вычитал в одной статье, что на FIBPlus есть компонент для такого рода дел под названием TpFIBErrorHandler, там даже целая статья посвящена тому как пользоваться этим компонентом и как обработку для любых constraint'ов делать.
А для InterBase есть что то подобное???? |
#8
|
||||
|
||||
Try Except это обработка исключительных ситуаций.
Когда база отключена например, или когда типу integr хотят присвоить значение 'Пепяка' TpFIBErrorHandler то что то вроде этого, но для ошибок именно в работе с фаербёрдом.Причем да, там есть возможность выбора типа обрабатываемых ошибок (то же отключение базы, либо глумление над PK,ввода дублирующегося значения для уникального поля). Все это есть в компонентах Fibplus вроде. Вам, насколько я понимаю, нужно проверять то что вы вводите на правильность, и если я понимаю правильно , то тут скорее нужен контроль вводимых значений. |