如何更改 TDBNavigator 组件的行为?
我想更改标准 DBNavigator 栏上插入按钮的行为,从数据集插入到追加。
我可以在 BeforeAction 事件中捕获按钮单击,执行附加操作等; 然后在 OnClick 事件中中止原始插入,但这似乎有点黑客。 还有更好的想法吗? 我正在使用 D6(已行驶 500,000 公里,并且仍然强劲......)。
感谢您的任何建议
问候,
PhilW。
I would like to change the behaviour of the insert button on the standard DBNavigator bar, from a dataset insert to append.
I could trap the button click in the BeforeAction event, do the append, etc; and then in the OnClick event abort the original insert, but this seems a bit of a hack. Any better ideas? I'm using D6 (500,000 kms on the clock, and still going strong...).
Thanks for any advice
Regards,
PhilW.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在大多数数据库中,插入和追加之间没有区别。 进行实际的物理插入意味着实际上移动所有数据,从插入新行的位置开始,减小一行的大小,然后将该新行写入新打开的位置。 由于所有磁盘活动,这将非常慢。
相反,数据库执行追加操作,将数据写入物理文件的末尾,索引顺序控制行在文件中正确位置的显示方式。
因此,对于大多数意图和目的,您可能已经获得了附加而不是插入,无论您使用哪种方法或 DBNavigator 上的按钮显示什么。 是索引让它看起来不一样。
您可以通过创建一个没有索引的数据库来检查其有效性,并尝试执行几次插入和追加,并在每次操作后仔细检查数据。
There is no difference in most databases between insert and append. Doing an actual physical insert would mean actually moving all data, starting with the place the new row would be inserted, down the size of one row, and then writing that new row in the newly open spot. This would be very slow because of all of the disk activity.
Databases instead do an append, which writes the data to the end of the physical file, and the index order controls the way the row appears to be positioned in the correct place in the file.
So for most intents and purposes, you're probably already getting an append instead of an insert, regardless of which method you use or what the button on the DBNavigator says. It's the index that makes it appear otherwise.
You can check that for validity by creating a database without an index, and try doing both an insert and an append a few times, examining the data carefully after every operation.
@TOndrej:太棒了! 我不欣赏这种技术。 谢谢!
@Ken White:我理解你的观点,但在视觉上对我的用户来说它是有区别的 - DBNavigator 控制 DBGrid,在大多数情况下,网格中有大量未使用的行。 让新记录出现在网格底部而不是出现在当前记录所在位置的上方似乎更加一致。 但谢谢你的回答。
问候,
菲尔W.
@TOndrej: Great! I hadn't appreciated this technique. Thanks!
@Ken White: I understand your point, but visually to my users it makes a difference - the DBNavigator controls a DBGrid where, in the majority of cases, there is plenty of unused rows in the grid. It appears to be more consistent to have new records appear at the bottom of the grid rather then just above where ever the current record is at that moment. But thanks for your answer.
Regards,
PhilW.
您可以从 TDBNavigator 派生您自己的类并重写 BtnClick 方法。
或者,为了快速而肮脏的修复,您可以在运行时更改插入按钮的单击处理程序,例如:
You could derive your own class from TDBNavigator and override BtnClick method.
Or, for a quick and dirty fix, you could change the insert button's click handler at runtime, e.g.: