You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将JSON/INI配置文件中的设置导入到ABL程序中?

用配置文件替代&global-define实现属性便捷调整

原本项目中用&global-define定义属性,修改起来很不方便,我计划把所有变量移到配置文件中,通过程序导入实现便捷调整。

最初的.ini文件尝试

我首先考虑用settings.ini作为配置文件:

port = 19995

对应的程序代码:

import settings.ini .
define variable iPort as integer no-undo .
iPort = port .

逐行读取.ini的低效方案

我试过逐行读取.ini文件,根据属性名给变量赋值,但变量数量多的时候这种方法效率很低:

input from value("settings.ini") .
repeat:
    import unformatted vLine.
    iIndex = index(vLine, "=") .
    cPropertyName = trim (substring (vLine, 1, iIndex - 1)) .
    cPropertyValue =  trim (substring (vLine, iIndex + 1)) .
    case cPropertyName:
        when "port" then 
            if cPropertyValue <> "" then iPort = cPropertyValue .
            else iPort = "" . 
    end case.
end.
input CLOSE.

仅Windows可用的方案

我还找到过一个仅适用于Windows系统的解决方案。

当前使用的JSON+临时表方案

目前我采用了基于临时表的JSON方案,实现起来更高效:

程序代码(procedure.p)

define temp-table ttSettings no-undo
    field port as integer .
temp-table ttSettings:read-json ("file", "settings.json").
find first ttSettings .
message ttSettings.port view-as alert-box.

配置文件(settings.json)

{
    "port": 19995
}

内容的提问来源于stack exchange,提问作者Goodie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:11:00