Files
playbook/skills/tsl-api-reference/references/codegen/builtin/object.md
T
csh 9010829c6d feat(tsl-api-reference): expand and reorganize api catalog
Flatten builtin pages, add third-party and platform scopes, and import financial and data warehouse references.

Keep the existing generated index without rebuilding after signature normalization.
2026-08-10 18:26:24 +08:00

88 lines
1.8 KiB
Markdown

# Builtin - 对象
## `createObject(class_name, ...)`
声明:function
创建一个已在 TSL 语言中注册的对象,类名或类类型无效时调用出错
<!-- tags: 对象 创建 实例 类 -->
| 参数 | 类型 | 说明 |
| ------------ | ----------------- | -------------------------------------------------------------- |
| `class_name` | string\|classtype | 已注册的对象类名,或通过 `class()``findClass()` 获得的类类型 |
| `...` | any | 可选。按顺序传给类构造函数的参数 |
返回:tslobject
### 示例
范例01:向构造函数传递参数
```tsl
obj := createObject('CreationExample', 42);
echo obj.value, "\n";
type CreationExample = class
public
value;
function create(initial_value);
begin
value := initial_value;
end;
end;
// 输出:42
```
## `findClass(class_name)`
声明:function
按名称查找类,找不到时返回 `0`
| 参数 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `class_name` | string | 类名称 |
返回:tclass\|integer
### 示例
范例01:查找脚本中声明的类
```tsl
class_value := findClass("DemoClass");
echo class_value <> 0;
// 输出:1
type DemoClass = class
end;
```
## `findClass(class_name, obj)`
声明:function
将对象转换为指定类,类不匹配时返回 `0`
| 参数 | 类型 | 说明 |
| ------------ | ------ | ------------ |
| `class_name` | string | 类名称 |
| `obj` | object | 要转换的对象 |
返回:object\|integer
### 示例
范例01:转换为指定类
```tsl
obj := new DemoClass();
typed_obj := findClass("DemoClass", obj);
echo typed_obj <> 0;
// 输出:1
type DemoClass = class
end;
```