Files
WorkNote/SanPinPLM/相关操作/4.0-other/200.Delphi脚本.md
2025-07-10 10:53:30 +08:00

110 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 介绍
在窗体表单或对象常规属性中支持 `Delphi` 脚本来实现一些特性化操作
# 脚本编辑器
这是一个编辑、检查脚本的窗体
由主菜单、工具栏、 [控件区](#控件区) 、 [脚本编辑区](#脚本编辑区) 、 [函数/变量区](#函数/变量区) 、 [错误提示区](#错误提示区) 组成,界面如下图:
![image-20240621100850228](assets/image-20240621100850228.png)
## 布局介绍
### 文件
保存或者关闭脚本编辑器
操作:检查语法正确性
查找/替换/查找下一个TXT文本功能
设置:
1. 修改 Tab 键跳转列数:设置缩进列数
2. 工具栏:显示脚本编辑器常用操作
### 控件区
显示源窗体中的编辑控件,双击控件节点时,在 [脚本编辑器](#脚本编辑器) 的当前光标位置增加控件名称,支持节点拖动
![](assets/Pasted%20image%2020250225085445.png)
### 脚本编辑区
编辑脚本的地方。 编辑时支持模糊匹 **配控件区** 的控件名和 **函数/变量区** 的函数或变量名;
如果文本是控件名,输入 “ . ” 将提示控件支持的属性或方法
按 “ Tab ” 键支持选择文本的定长缩进
按 “ Shift + Tab ” 键支持选择文本的定长反缩进
支持文本搜索、搜索替换功能
使用的脚本为 `Delphi` 脚本,参考代码如下所示,作用为 [多属性值拼接至另一属性中](999.Delphi脚本记录.md#多属性值拼接至另一属性中)
```Delphi
uses MyClass,Variables,BaseUtil,CommonFunc,DataConst,CFFrm,CFSimplePropFrm,Forms,StdCtrls,Variants,SysUtils,Classes,Controls,Dialogs,
CHostIntf,ProductClas,DocClas,LoginClas,VirtualTrees,CEntClas,PathClas;
var
StringList: TStringList;
begin
// 创建和初始化TStringList
StringList := TStringList.Create;
try
// 如果fedtusr_substrate_id的值不为空则将值添加到StringList中
if fedtusr_substrate_id.Text <> '' then
StringList.Add(fedtusr_substrate_id.Text);
if fedtusr_substrate_id2.Text <> '' then
StringList.Add(fedtusr_substrate_id2.Text);
if fedtusr_substrate_id3.Text <> '' then
StringList.Add(fedtusr_substrate_id3.Text);
if fedtusr_substrate_id4.Text <> '' then
StringList.Add(fedtusr_substrate_id4.Text);
// 转换为逗号分隔的字符串
mmmusr_substrate2.Text := StringList.DelimitedText; // 默认使用逗号作为分隔符
// 如果需要指定其他分隔符可以设置Delimiter属性
// StringList.Delimiter := ';'; // 设置分隔符为分号
// Result := StringList.DelimitedText;
finally
StringList.Free;
end;
end.
```
### 函数/变量区
显示系统支持的变量和函数,双击节点时,在 **脚本编辑区** 的当前光标位置增加变量或函数名称,鼠标移到树节点时,提示信息窗显示变量类型或函数原型,支持节点拖动
![](assets/Pasted%20image%2020250710101403.png)
#### 执行sql获取字符串
此函数作用为执行 `SQL` 语句,去获取字符串结果
案例如下
```delphi
chiGetFieldValueBySql('select top 1 usr_sqlmj from pdmitem where usr_sqlmj like ''%' + str + '%''')
```
#### 执行sql填充下拉框
此函数作用为执行 `SQL` 语句,将获取到的结果作为下拉选项提供给下拉框,需要写入两个参数,第一个为 `SQL` 语句,第二个为要接收结果的控件(接收结果的控件,其 **按钮类型** 必须为 **下拉**,详见 [根据输入内容在数据库中查询,获取查询结果作为下拉列表以供选择](999.Delphi脚本记录.md#根据输入内容在数据库中查询,获取查询结果作为下拉列表以供选择) 说明
案例如下:
```delphi
chiFillComboBox('select distinct top 10 usr_sqlmj from pdmitem where usr_sqlmj like ''%' + str + '%''',fedtusr_sqlmj);
```
### 错误提示区
执行 **保存****检查语法正确性** 命令时,如果脚本存在错误,则错误信息被显示在 **错误提示区**,双击错信息行时,在 **脚本编辑区** 中对于的错误行用红色背景标记
![](assets/Pasted%20image%2020250710101604.png)