界面如图:

代码如下:

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7. Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,IniFiles; //添加库 IniFiles
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. Button1: TButton;
  12. Button2: TButton;
  13. Label1: TLabel;
  14. Label2: TLabel;
  15. Label3: TLabel;
  16. Label4: TLabel;
  17. Edit1: TEdit;
  18. Edit2: TEdit;
  19. Edit3: TEdit;
  20. CheckBox1: TCheckBox;
  21. procedure Button1Click(Sender: TObject);
  22. procedure Button2Click(Sender: TObject);
  23. private
  24. { Private declarations }
  25. public
  26. { Public declarations }
  27. end;
  28.  
  29. var
  30. Form1: TForm1;
  31. var
  32. filepath :string;
  33. myinifile : TIniFile;
  34. implementation
  35.  
  36. {$R *.dfm}
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. begin
  40. try
  41. filepath := ExtractFilePath(Paramstr()) + 'serverlist.ini'; //获取当前路径+文件名
  42. myinifile := Tinifile.Create(filepath); //创建文件
  43. except
  44. ShowMessage('LOADINI打开配置文件失败');
  45. Exit;
  46. end;
  47. {写入}
  48. myinifile.WriteString('ListServer1','ServerCount','');
  49. myinifile.WriteString('ListServer1','Name0','');
  50. myinifile.WriteString('ListServer1001','ServerCount','');
  51. myinifile.WriteString('ListServer1001','Name0',Edit1.Text);
  52. myinifile.WriteString('ListServer1001','IP0',Edit2.Text);
  53. myinifile.WriteInteger('ListServer1001','Port0',StrToInt(Edit3.Text));
  54. myinifile.WriteBool('Battle','Enable',False);
  55.  
  56. myinifile.WriteInteger('Resolution','width',);
  57. myinifile.WriteInteger('Resolution','height',);
  58. if CheckBox1.Checked = True then
  59. myinifile.WriteBool('WINDOW_MODE','MODE',True)
  60. else
  61. myinifile.WriteBool('WINDOW_MODE','MODE',False);
  62. ShowMessage('写入成功');
  63. end;
  64.  
  65. procedure TForm1.Button2Click(Sender: TObject);
  66. begin
  67. try
  68. filepath := ExtractFilePath(Paramstr()) + 'serverlist.ini'; //获取当前路径+文件名
  69. myinifile := Tinifile.Create(filepath); //创建文件
  70. except
  71. ShowMessage('LOADINI打开配置文件失败');
  72. Exit;
  73. end;
  74. {读取}
  75. Edit1.Text:= myinifile.ReadString('ListServer1001','Name0','');
  76. Edit2.Text:= myinifile.ReadString('ListServer1001','IP0','');
  77. Edit3.Text:= myinifile.ReadString('ListServer1001','Port0','');
  78. end;
  79.  
  80. end.

Delphi 对ini文件的操作的更多相关文章

  1. Delphi对ini文件的操作

    一.INI文件的结构:; 注释[小节名]关键字=值 INI文件允许有多个小节,每个小节又允许有多个关键字, “=”后面是该关键字的值. 值的类型有三种:字符串.整型数值和布尔值.其中字符串存贮在INI ...

  2. delphi对ini文件的操作(转载 万一)

    ini 文件操作记要(1): 使用 TIniFileunit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Gr ...

  3. Delphi关于记录文件的操作

    http://www.cnblogs.com/railgunman/archive/2010/08/16/1801004.html Delphi关于记录文件的操作   本例子几个变量的说明TFileR ...

  4. delphi中ini 文件操作记要(1): 使用 TIniFile

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  5. delphi读取ini文件

    ini文件在系统配置及应用程序参数保存与设置方面,具有很重要的作用,所以可视化的编程一族,如vb.vc.vfp.delphi等都提供了读写ini文件的方法,其中delphi中操作ini文件,最为简洁, ...

  6. delphi 基础之三 文件流操作

    文件流操作 Delphi操作流文件:什么是流?流,简单来说就是建立在面向对象基础上的一种抽象的处理数据的工具.在流中,定义了一些处理数据的基本操作,如读取数据,写入数据等,程序员是对流进行所有操作的, ...

  7. Delphi 实现Ini文件参数与TEdit和TCheckBox绑定(TSimpleParam)

    在实际工作中,常遇到对Ini参数的修改,显示与保存问题. 如果手工写代码,会有很大的工作量. 本例把ini文件的参数与控件绑定起来,以达到方便使用的目的. 本例程共有2个单元 uSimpleParam ...

  8. C#实现.ini文件读写操作

    1.ini文件是什么?        见百度百科:https://baike.baidu.com/item/ini%E6%96%87%E4%BB%B6/9718973?fr=aladdin 2.C#语 ...

  9. VC++ 实现INI文件读写操作

    转载:https://blog.csdn.net/fan380485838/article/details/73188420 在实际项目开发中,会用ini配置文件,在此总结一下对ini读写操作 一:读 ...

随机推荐

  1. CocoaPods 中删除不需要的第三方

    1...打开Podfile  找到不需要的类库,直接删除 2...打开终端cd到当前项目的根目录下重新执行pod install --verbose --no-repo-update命令(更新一下) ...

  2. 页面对象(Page Object)模式

    内容转载自 https://www.cnblogs.com/yytesting/p/6973474.html 页面对象(Page Object)模式是目前自动化测试领域普遍使用的设计模式之一,此模式可 ...

  3. MAVEN中的Scope

    Dependency Scope 在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用6个值: *im ...

  4. Keil中查看.c和.h文件的路径

    方法一: 选择任意一个文件,然后点击右键,选择"Option for File xxx"即可查看该文件的路径. 方法二: 单击任意一个文件,然后点击右键,选择"Open ...

  5. vue动态绑定src加字符串拼接

    关键点 1.img中的src的字符串动态拼接 2.style中的background属性赋值 一.img中的src的字符串动态拼接 1.问题是这样子的,瞧瞧 基本网络链接 : http://openw ...

  6. js点滴3 vs vue

    web Components 学习之路 https://www.cnblogs.com/zhaowinter/p/5447246.html vue学习指路. vue全局配置. ignoredEleme ...

  7. Elasticsearch+Mongo亿级别数据导入及查询实践

    数据方案: 在Elasticsearch中通过code及time字段查询对应doc的mongo_id字段获得mongodb中的主键_id 通过获得id再进入mongodb进行查询   1,数据情况: ...

  8. es6中promise ALL Race Resolve Reject finish的实现

    function mypromise(func){ this.statue = "pending"; this.data = null; this.resolveCallback ...

  9. 什么是LDAP?

    LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的,但是简单多了并且可以根据需要定制.与X ...

  10. L - Non-Prime Factors (质数筛选+因子分解)

    In many programming competitions, we are asked to find (or count the number of) Prime Factors of an ...