原文 http://blog.chinaunix.net/uid-23480430-id-3016899.html

InnoSetup支持一些INI文件操作函数,

例如GetIniString,IniKeyExists等等。。
利用这些已有的函数,读取/删除/检测键值是否存在,都没有问题。
 
但是,想要列出一个INI文件有哪些Sections, 
某个Section下面有哪些键值,
就没法做到了。
 
所幸InnoSetup有个很好用的 LoadStringsFromFile 函数,
用来读取文本文件很方便,读INI自然不在话下。
然后再做一点简单的解析,就能得到一个INI中所有的sections和键值了。
 
实现两个函数如下:
 
读取INI文件中有哪些Sections, 并将其名字存放到 Arr数组里。
procedure IniGetSections(var Arr: Array of String; const Path: String);
 
读取INI文件的某个Section底下,有哪些键名,并将这些键名存放到Arr数组里。
procedure IniGetKeys(var Arr: Array of String; const Path: String; const Section: String);
 
  1. procedure ArrayAddStr(var Arr: Array of String; Str: String);
  2. var
  3. Len: Longint;
  4. begin
  5. Len := GetArrayLength(Arr);
  6. SetArrayLength(Arr, Len + 1);
  7. Arr[Len] := Str;
  8. end;
  9. //-- INI
  10. function IniGetSectionName(Line: String; var Name: String): Boolean;
  11. var
  12. P0, P1: Integer;
  13. begin
  14. Line := TrimLeft(Line);
  15. P0 := Pos('[', Line);
  16. P1 := Pos(']', Line);
  17. if (P0 = 1) and (P1 > P0 + 1) then begin
  18. Name := Copy(Line, P0 + 1, P1 - P0 - 1);
  19. Result := True;
  20. end
  21. else
  22. Result := False;
  23. end;
  24. function IniGetKeyName(Line: String; var Name: String): Boolean;
  25. var
  26. P0, P1: Integer;
  27. begin
  28. Line := TrimLeft(Line);
  29. P0 := Pos('=', Line);
  30. P1 := pOS(';', Line); //; is start of comment
  31. if (P0 > 1) and ((P1 = 0) or (P1 > P0)) then begin
  32. Name := Trim(Copy(Line, 1, P0 - 1));
  33. Result := True;
  34. end
  35. else
  36. Result := False;
  37. end;
  38. procedure IniGetSections(var Arr: Array of String; const Path: String);
  39. var
  40. i: Longint;
  41. Name: String;
  42. Lines: Array of String;
  43. begin
  44. SetArrayLength(Arr, 0);
  45. if not LoadStringsFromFile(Path, Lines) then exit;
  46. for i := 0 to GetArrayLength(Lines) - 1 do begin
  47. if IniGetSectionName(Lines[i], Name) then ArrayAddStr(Arr, Name);
  48. end;
  49. end;
  50. procedure IniGetKeys(var Arr: Array of String; const Path: String; const Section: String);
  51. var
  52. i: Longint;
  53. Name: String;
  54. Lines: Array of String;
  55. begin
  56. SetArrayLength(Arr, 0);
  57. if not LoadStringsFromFile(Path, Lines) then exit;
  58. for i := 0 to GetArrayLength(Lines) - 1 do begin
  59. if IniGetSectionName(Lines[i], Name) then begin
  60. if CompareText(Name, Section) = 0 then break;
  61. end;
  62. end;
  63. if i < GetArrayLength(Lines) then begin
  64. { The section is }
  65. for i := i + 1 to GetArrayLength(Lines) - 1 do begin
  66. if IniGetSectionName(Lines[i], Name) then break
  67. else if IniGetKeyName(Lines[i], Name) then ArrayAddStr(Arr, Name);
  68. end;
  69. end;
  70. end;

InnoSetup中枚举出INI文件的所有sections和键值的更多相关文章

  1. 向php文件中添加php.ini文件

    向php文件中添加php.ini文件 默认情况下,php是没有php.ini配置文件的,必须手工添加php.ini文件 在php安装目录中,复制php.ini文件到/usr/local/php/lib ...

  2. [转载]windows7中没用boot.ini文件而是改用BCDEDIT来配置了

    原文地址:windows7中没用boot.ini文件而是改用BCDEDIT来配置了作者:开心骝哥 本人安装的Win7,因为机上有两个系统,一个dos系统,一个win7系统,开机时总是会在系统选择的界面 ...

  3. win7下iis中配置php.ini文件

    将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...

  4. web安全之php中常见的INI文件配置

    php.ini 在 PHP 启动时被读取.对于服务器模块版本的 PHP,仅在 web 服务器启动时读取 一次.对于 CGI 和 CLI 版本,每次调用都会读取. * Apache web 服务器在启动 ...

  5. IDEA中怎么创建ini文件

    首先博主在这使用的是idea的2019.3.2的版本,不知道的话可以打开help菜单的about查看 第一步: 具体需要在setings安装ini插件 第二步: 在File Types中查看ini,没 ...

  6. 获取ini文件所有的Sections和Keys

    获取ini文件中所有的Sections和Keys,并以pair对的方式存入到vector中 #include <iostream> #include <windows.h> # ...

  7. 利用FastJson,拼接复杂嵌套json数据&&直接从json字符串中(不依赖实体类)解析出键值对

    1.拼接复杂嵌套json FastJson工具包中有两主要的类: JSONObject和JSONArray ,前者表示json对象,后者表示json数组.他们两者都能添加Object类型的对象,但是J ...

  8. Nginx中修改php.ini的上传设置upload_max_filesize的值

    普遍的网络越来越快,以前小家子气的2M上传限制慢慢变得不合时宜了.最近就把2M的限制直接提升到了20M...代码层面很快就修改好了,没什么可说的.但是上线的话还得修改一下服务器的配置.服务器是Ngin ...

  9. 关于C#操作INI文件的总结

    原文:关于C#操作INI文件的总结   INI文件其实是一种具有特定结构的文本文件,它的构成分为三部分,结构如下: [Section1]key 1 = value2key 1 = value2--[S ...

随机推荐

  1. FTP 上传文件

    有时候需要通过FTP同步数据文件,除了比较稳定的IDE之外,我们程序员还可以根据实际的业务需求来开发具体的工具,具体的开发过程就不细说了,这里了解一下通过C#实现FTP上传文件到指定的地址. /// ...

  2. PHP中文汉字验证码

    hb.ttf换成随便你自己下载的ttf Header("Content-type: image/PNG"); $str="的一是在了不和有大这主中人上为们地个用工时要动国 ...

  3. Spring事务管理器分类

    Spring并不直接管理事务,事实上,它是提供事务的多方选择.你能委托事务的职责给一个特定的平台实现,比如用JTA或者是别的持久机制.Spring的事务管理器可以用下表表示: 事务管理器的实例 目标 ...

  4. 编写jeb插件打印目标方法的交叉引用

    jeb插件的编写,文档在文件夹\jeb_1.5\doc\apidoc. 我这里的目的是回溯sendTextMessage等敏感api的调用路径,实现代码如下: from jeb.api import ...

  5. 【Nginx】事件和连接

    不同的操作系统相应不同的事件驱动机制.在Linux 2.6之后使用epoll机制.相应的事件驱动模块是ngx_epoll_module.Nginx的ngx_event_core_module模块依据操 ...

  6. ibatis之##与$$的 使用

    /** 主要讲一下ibatis中$$的使用: 是为了传递参数; 参数一定在Action层用''包裹起来: */ List <SysRole> userList= systemService ...

  7. iOS程序的加载过程

    1.执行main函数2.执行UIApplicationMain函数1> 创建一个UIApplication对象(UIApplication是整个程序的象征)一个应用只有一个application ...

  8. visual studio 一直显示正在准备解决方案

    首先重启电脑,无法解决的情况下执行以下步骤: Kill Visual Studio Open Visual Studio without loading a solution Disable Ankh ...

  9. View not attached to window manager

    java.lang.IllegalArgumentException: View not attached to window manager 在用ProgressDialog的时候,任务结束后Dis ...

  10. ios--图片处理(修改、保存)UIGraphicsBeginImageContext

    http://www.th7.cn/Program/IOS/201407/250904.shtml