Delphi - ClientDataSet - 验证数据
我在 Delphi 7 中有一个应用程序,它使用 clientdataset,并对其进行多项操作。 ClientDataSet 链接到 Intraweb 网格。
我在 ClientDataSet 上进行插入或编辑。如何验证 clientdataset 中每个字段引入的数据?我无法验证用户在 Web 表单上的输入,因此我必须使用 ClientDataSet 事件进行验证。
LE:我想在用户输入时验证数据。不在 onbeforepost 事件中。因此,我将 clientdataset 放入编辑/插入中。用户在网格中进行输入,我想验证 clientdataset 中该行的数据,如下图所示:
第一列是字符串,第二列是整数,第三列也是整数。现在,我想在用户输入后验证第三列。必须仅通过使用客户端数据集事件/黑客来完成此验证(如果可能)。
I have an application in Delphi 7 which is using a clientdataset, and make several operations on it. ClientDataSet is linked to an Intraweb Grid.
I make an insert or an edit on the ClientDataSet. How can I verify the data introduced in the clientdataset for each field? I can not verify the input from the user on the webform, so I must make validation using ClientDataSet events.
LE: I want to validate data when the user make the input. Not at the onbeforepost event. So, I put the clientdataset in the edit/insert. User make an input in the grid, and I want to validate the data for that row in the clientdataset like in the image bellow:
first column is string, second is integer, the third one is also an integer. Now, I want to validate the third column after the user make the input. This validation must be done (if it is possible), only by using clientdataset events/hacks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该处理 TClientDataset BeforePost 事件,如果数据无效,请使用 < a href="http://docwiki.embarcadero.com/VCL/en/SysUtils.Abort" rel="nofollow">中止方法
You should handle TClientDataset BeforePost event, and if data is not valid use abort method
TField 有一个用于此目的的 OnValidate 事件。它还有一个 CustomConstrain 属性,可以使用类似 SQL 的语法进行约束。如果没有给出值,DefaultExpression 将允许您选择一个值。这些对于单字段验证很有用。如果您需要跨多个字段进行更复杂的检查,则必须使用数据集或数据源事件。
无论如何,如果 Intraweb 网格向服务器发送整个记录而不是单个字段编辑,则您可能不会验证在网格中输入的字段,而是在客户端添加代码。
TField has an OnValidate event for that purpose. It has also a CustomConstrain property that can use a SQL like syntax for constraints. DefaultExpression will let you select a value if no value is given. These are usuful for single-field validation. If you need more complex checks across more than one field, then you have to use dataset or datasource events.
Anyway, if the Intraweb grid sends the server whole records and not single fields edits, you may not validate fields as they are entered in the grid but adding code client side.
如果您想要基于字段的验证,您可以处理将网格连接到数据集的 TDatasource 的 OnDataChange 事件。每当用户更改字段时都会触发此操作。您应该意识到它也会在其他一些情况下被触发。
If you want a field based validation, you can handle the OnDataChange event of the TDatasource connecting the grid to the dataset. This will be triggered whenever a field has been changed by the user. You should be aware that it will also be triggered in some other situations.