@@ -4,6 +4,8 @@
|
||||
|
||||
## 本篇职责
|
||||
|
||||
<!-- section-id: syntax-18-001 -->
|
||||
|
||||
回答下面这些“写法已经会了,但运行起来为什么这样”的问题:
|
||||
|
||||
- `unit` 什么时候进入 `initialization`
|
||||
@@ -15,6 +17,8 @@
|
||||
|
||||
## 核心规则
|
||||
|
||||
<!-- section-id: syntax-18-002 -->
|
||||
|
||||
- 完整 `unit` 形态可以包含 `interface`、`implementation`、`initialization`、`finalization`,并以 `end.` 结束。
|
||||
- `initialization` 在 `unit` 第一次被实际使用时触发,不是只因为顶层写了 `uses` 就立刻执行。
|
||||
- `finalization` 会在脚本结束前触发。
|
||||
@@ -33,8 +37,12 @@
|
||||
|
||||
## 示例与行为
|
||||
|
||||
<!-- section-id: syntax-18-003 -->
|
||||
|
||||
### `unit` 生命周期
|
||||
|
||||
<!-- section-id: syntax-18-004 -->
|
||||
|
||||
<!-- tags: 模块什么时候初始化, unit 状态, 加载时机, 只初始化一次 -->
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
@@ -99,6 +107,8 @@ FINAL
|
||||
|
||||
### `unit` 成员的读取边界
|
||||
|
||||
<!-- section-id: syntax-18-005 -->
|
||||
|
||||
<!-- tags: 读模块常量, 访问 unit 成员, 限定名读取 -->
|
||||
|
||||
直接限定读取:
|
||||
@@ -242,6 +252,8 @@ DemoUnit.unit_counter := 13;
|
||||
|
||||
### `tslfilename()`
|
||||
|
||||
<!-- section-id: syntax-18-006 -->
|
||||
|
||||
<!-- tags: 当前脚本路径, 我在哪个文件, 取自身文件名 -->
|
||||
|
||||
代码块身份:可直接照写示例
|
||||
@@ -257,6 +269,8 @@ writeLn(tslfilename());
|
||||
|
||||
### `namespace` 与默认命名空间
|
||||
|
||||
<!-- section-id: syntax-18-007 -->
|
||||
|
||||
<!-- tags: 命名空间, 同名函数归属, 默认空间, 全局与命名空间冲突 -->
|
||||
|
||||
把默认命名空间、脚本覆盖、以及“全局函数与命名空间函数同名”的三组结论压成同一套最小实验:
|
||||
@@ -304,6 +318,8 @@ writeLn(Hello());
|
||||
|
||||
### `-LIBPATH`
|
||||
|
||||
<!-- section-id: syntax-18-008 -->
|
||||
|
||||
<!-- tags: 查找路径, 找不到文件, 搜索顺序, 命令行指定路径 -->
|
||||
|
||||
查找顺序:
|
||||
@@ -359,6 +375,8 @@ tsl .\main.tsl -LIBPATH "D:\libA\,D:\libB\"
|
||||
|
||||
### `syssettsllibpath()` 与 `sysgettsllibpath()`
|
||||
|
||||
<!-- section-id: syntax-18-009 -->
|
||||
|
||||
<!-- tags: 运行时改查找路径, 读取库路径 -->
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
@@ -378,6 +396,8 @@ writeLn(call("FnB"));
|
||||
|
||||
### `tsl.conf` 的 `Libpath=`
|
||||
|
||||
<!-- section-id: syntax-18-010 -->
|
||||
|
||||
<!-- tags: 配置文件, 配路径, tsl.conf 怎么写 -->
|
||||
|
||||
代码块身份:配置片段 / 概念骨架
|
||||
@@ -468,6 +488,8 @@ writeLn(Hello());
|
||||
|
||||
## 禁止项
|
||||
|
||||
<!-- section-id: syntax-18-011 -->
|
||||
|
||||
- 把 `DemoUnit.var_name := value` 当成可用的限定赋值。
|
||||
- 以为 `implementation` 里的常量和变量一定都不能从 `DemoUnit.Member` 读到。
|
||||
- 以为 `findFunction("DemoUnit")` 暴露的成员范围和 `DemoUnit.Member` 完全相同。
|
||||
|
||||
Reference in New Issue
Block a user