@@ -4,10 +4,14 @@
|
||||
|
||||
## 本篇职责
|
||||
|
||||
<!-- section-id: syntax-20-001 -->
|
||||
|
||||
回答“写普通 TSL/TSF 脚本时,哪些内置对象可以直接创建,最小可用接口是什么,哪些对象其实依赖特定运行上下文”。
|
||||
|
||||
## 核心规则
|
||||
|
||||
<!-- section-id: syntax-20-002 -->
|
||||
|
||||
- `TStringList` 可以直接用 `new TStringList()` 创建。
|
||||
- `TStringList` 支持数字下标、字符串键下标、`Count` 和 `Add(...)`。
|
||||
- `THashedStringList` 可以直接创建,最小用法与 `TStringList` 接近,适合按名称快速取值。
|
||||
@@ -27,8 +31,12 @@
|
||||
|
||||
## 可直接照写示例
|
||||
|
||||
<!-- section-id: syntax-20-003 -->
|
||||
|
||||
### `TStringList`
|
||||
|
||||
<!-- section-id: syntax-20-004 -->
|
||||
|
||||
<!-- tags: 字符串列表, 存一批字符串, 键值文本, 逗号文本 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -50,6 +58,8 @@ writeLn(list.Count);
|
||||
|
||||
### `THashedStringList`
|
||||
|
||||
<!-- section-id: syntax-20-005 -->
|
||||
|
||||
<!-- tags: 哈希列表, 快速查名字, 大量键查找 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -69,6 +79,8 @@ writeLn(list["B"]);
|
||||
|
||||
### `TStream` 家族的最小可靠入口:`TMemoryStream` 与 `TFileStream`
|
||||
|
||||
<!-- section-id: syntax-20-006 -->
|
||||
|
||||
<!-- tags: 内存流, 文件流, 读写文件, 二进制读写, 存到文件 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -126,6 +138,8 @@ writeLn(ifObj(base));
|
||||
|
||||
### `TCipher`
|
||||
|
||||
<!-- section-id: syntax-20-007 -->
|
||||
|
||||
<!-- tags: 加密解密, 对称加密, 密文 -->
|
||||
|
||||
无参创建反例:
|
||||
@@ -161,6 +175,8 @@ writeLn(cipher.Decrypt(enc));
|
||||
|
||||
### `TRsa`
|
||||
|
||||
<!-- section-id: syntax-20-008 -->
|
||||
|
||||
<!-- tags: 非对称加密, 公钥私钥, 签名, RSA -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -184,6 +200,8 @@ writeLn(length(rsa.PrivateKey) > 0);
|
||||
|
||||
### `TIniFile` 与 `TMemIniFile`
|
||||
|
||||
<!-- section-id: syntax-20-009 -->
|
||||
|
||||
<!-- tags: 配置文件读写, ini, 读配置项 -->
|
||||
|
||||
磁盘 INI 文件:
|
||||
@@ -220,6 +238,8 @@ writeLn(ini.ReadString("S", "K", ""));
|
||||
|
||||
### `MailMsg` 与 `MessagePart`
|
||||
|
||||
<!-- section-id: syntax-20-010 -->
|
||||
|
||||
<!-- tags: 发邮件, 邮件正文, 附件 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -249,6 +269,8 @@ writeLn(part.Body);
|
||||
|
||||
### `TWebRequest` / `TWebResponse` 的普通脚本边界
|
||||
|
||||
<!-- section-id: syntax-20-011 -->
|
||||
|
||||
<!-- tags: 网页请求, http 对象, web 环境限制 -->
|
||||
|
||||
代码块身份:反例 / 不可照写
|
||||
@@ -266,6 +288,8 @@ resp := new TWebResponse();
|
||||
|
||||
## 本页不生成的范围
|
||||
|
||||
<!-- section-id: syntax-20-012 -->
|
||||
|
||||
- `FTP` / `SMTP` / `POP3` 的连接、认证、上传下载、发送邮件和收取邮件流程。
|
||||
- `TWebRequest` / `TWebResponse` 的 Web 请求响应流程。
|
||||
- `TCookie` / `TCookieCollection`。
|
||||
@@ -277,6 +301,8 @@ resp := new TWebResponse();
|
||||
|
||||
## 禁止项
|
||||
|
||||
<!-- section-id: syntax-20-013 -->
|
||||
|
||||
- 不要直接把 `new TStream()` 写成普通脚本里的可靠创建方式。
|
||||
- 不要无参创建 `TCipher`;最小可靠写法是 `new TCipher(2)` 后再设置 `Password`。
|
||||
- 不要把 `TWebRequest` / `TWebResponse` 写进普通脚本模板。
|
||||
|
||||
Reference in New Issue
Block a user