Right now I’m struggling to solve a bug that caused by the dataset mode at Delphi (using ADODataset),
details as below for the add button mechanism :
I already set the adodataset to append mode at the save button :
when I click the save button, an error appears that:
The adodataset not in edit/insert mode
I already used this mechanism at the other form and it works
note: I already tried setting the adodataset mode to insert, but still faced the same error

1 Answer 1
What @kobik said.
Your problem is most likely being caused by something you haven’t told us in your q. I think the important thing is for you to find out how to debug this sort of thing yourself, so that even if you don’t understand the cause, you can at least isolate it and provide better information when you ask for help here. So I’m going to outline how to do that.
In your Project Options, check the box «Use Debug DCUs»
Set up two event handlers, for your ADODataSetWorkingDetails’s AfterPost and AfterScroll events, put a some «do nothing» code in both of them (to stop the IDE removing them). Put a debugger breakpoint on the first line inside the AfterScroll handler, but not (yet) the AfterScroll one.
Compile and run your program.
You should find that somewhere after you call Append but before you click your Save button, the debugger stops on your AfterPost breakpoint.
When it does, go to View | Debug windows | Call stack . This will show you a list of program lines, the one at the top being the one closest to where the breakpoint tripped. This will likely be deep inside the VCL’s run-time code (which is why I said to check «Use Debug DCUs». Scroll down the list towards the bottom, and eventually you should come to a line which is the cause of why Post was called.
If it isn’t obvious to you why the AfterPost event was called, put a breakpoint on your Append line and run the program again. When this breakpoint trips, put another breakpoint inside your AfterScroll event, resume the program by pressing F9 and see if the AfterScroll breakpoint is hit. If it is, again view the Call stack and that should show you why it was called — if it isn’t obvious, then add the contents of tthe Call stack window to your q. If the cause is obvious, then change your code to avoid it.
The reason I’ve gone on about the AfterScroll event is that what isn’t obvious is that when your code causes a dataset to scroll, any pending change (because the dtaset is in dsInsert or dsEdit state will cause the change to be posted and you will then got the error you’ve quoted if you try to call Post on the dataset again. Calling Append initially sets a dataset into dsInsert state, btw.
See if you can at least identify what is causing your dataset to post before it is supposed to, and let us know in a comment to your q or this answer.
Btw, I strongly recommend that you get out of the habit of using the with construct in your code. Although it may save you a bit of typing, in the long term it will likely make bugs far more likely to happen and far harder to find.
Yegor, проверила Ваш код — работает корректно.
Только подправила
Тестировала на версии 3.4.1
Результаты тестирования во вложенных скриншотах (1 — до записи в БД, после записи БД).
На какой версии Вы работаете?
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
У меня тоже работает, не считая того, что вместо MessageBox надо писать
или обёртку из scr_WindowUtils
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
«Бондарь Наталия» написал: На какой версии Вы работаете?
ругается.
Я задумываться начинаю, может собака глубже зарыта, и своими неопытными ручками я tbl + sq + ds не по человечески связал :confused:?
Здесь всё просто (на сколько понял) Одна таблица с полем String (остальные по дефолту). Select Query завязанный на таблицу с селектами по ID и String. Ну и Dataset завязанный на Select Query с ключевым полем ID.
Ударьте по рукам пожалуйста если что не так 😐
Александр, прошу Вас, дабы полностью разрушить мои стереотипы пояснить моменты по поводу окон сообщений.
Привычного alert() декларированного в ECMAScript я не обнаружил. Случайно наткнувшись на MessageBox(‘Text’), ужаснулся и стал ностальгировать о Delphi (синтаксис идентичен)
- 1. Данные методы являются глобальными встроенными методами Terrasoft ( кроме ShowInformationDialog(‘Text’) явно не глобальный :smile:)?
- 2. И в чём принципиальная разница каждого? Только в гибкости настроек вывода (доп. кнопки, выбор иконки и т.п.) или что-то ещё?
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
Егор, покажите скриншоты всех трёх сервисов.
Идеология конфигурации Terrasoft 3.X такова, что методы встроенных глобальных объектов стараются использовать минимально. Взамен им в скриптах-библиотеках scr_Utils, scr_WindowUtils и других написаны функции-обёртки, часто с дополнительными возможностями или скрытием ненужных обычно параметров. Например, одному методу System.MessageDialog с кучей параметров соответствует семейство ShowInformationDialog, ShowErrorDialog, ShowWarningDialog с одним параметром — текстом сообщения.
Аналогично, вместо Services.GetNewItemByUSI лучше использовать функцию GetSingleItemByCode (она уже есть в какой-то библиотеке), не создающую лишних сущностей без необходимости.
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
«Зверев Александр» написал: Егор, покажите скриншоты всех трёх сервисов.
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
Метод MessageBox является одной из обёрток, о которых писал Александр. Его использование вполне уместно.
- Войдите или зарегистрируйтесь, чтобы оставлять комментарии
- Цитировать
Ошибка говорит о том, что свойство Dataset.State != dstInsert(dstEdit).
Это значит, что метод
Поставьте галочку в сервисе датасета «Добавление», а также определите первичное поле для отображения.
![]()
I have a master detail form, the table are connected in ms sql with cascade update deletes. I wan’t the form to open on a new record.
I have the following code in my form
If there are no records in the master table it works fine and adds a new record so the user can create a new invoice, but if there are records in the master table I get the following error «Dataset not in edit or in insert mode». I ahe tried AdoDatsetMaster.edit and AdoDatsetMaster.insert but I get the same error. and same result
If I click on ok and press f9, it keeps going and a new record is added.