delphi - Create a Procedure using a TClientDataset as a parameter
问题描述
I want to create a procedure in Delphi 2010.
This procedure will receive a TClientDataset 'cdTable1' parameter and an X Integer and it has to perform an action of close/open dataset:
if cdTable1.Active then cdTable1.Close;
cdTable1.Params.ParamByName('MyParameter').AsString:=X;
cdTable1.Open;
How can I define it and run it?
解决方案
Try this:
procedure TForm1.MyProcName(cds : TClientDataSet; X : Integer);
begin
if cds.Active then
cds.Close;
cds.Params.ParamByName('MyParameter').AsString := X;
cds.Open;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
MyProcName(cdTabel1, 1234);
end;
In the interface section, where TForm1 is defined, you have to add:
public
procedure MyProcName(cds : TClientDataSet; X : Integer);
If you are using a TDataModule, probably procedure MyProcName would find a nice place there instead of the form.
推荐阅读
- database - Postgres-XL 备用服务器
- reactjs - SVG 反应本机
- amazon-web-services - 添加新分区时如何不增加 Glue 中的表版本
- dictionary - 从元组和字符列表创建新字典
- python - 从 tiff 图像生成数组的问题
- javascript - 如何在 JavaScript 或 java 中创建和解析标签、长度、值 (TLV) 并在 Base64 中编码
- java - 如何在不卸载旧版本表单 Playstore 的情况下更新应用程序?
- sympy - Sympy微分方程:如何将一些lhs项剪裁到rhs?
- javascript - 如何为图表中的多个数据集共享相同的背景颜色?
- r - 过滤 dplyr 中的整个前两列