zoukankan      html  css  js  c++  java
  • ini写配置信息 列表框

     
     
     
    unit Unit1; 

    interface 

    uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs, StdCtrls; 

    type 
      TForm1 = class(TForm) 
        ListBox1: TListBox; 
        Button1: TButton; 
        Button2: TButton; 
        Memo1: TMemo; 
        Button3: TButton; 
        Button4: TButton; 
        procedure Button3Click(Sender: TObject); 
        procedure Button4Click(Sender: TObject); 
        procedure Button1Click(Sender: TObject); 
        procedure Button2Click(Sender: TObject); 
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end

    var 
      Form1: TForm1; 

    implementation 
     uses IniFiles; 
    {$R *.dfm} 

    var iniPath:string;//ini路径 
        fName:string;  //ini的文件名 
    procedure ListBoxToINI(const AINIFile, ASection: string; ListBox: TListBox); 
    var 
      INI: TINIFile; 
      I: Integer; 
    begin 
      INI := TINIFile.Create(AINIFile); 
      try 
        INI.EraseSection(ASection); 
        INI.WriteInteger(ASection, 'Count', ListBox.Items.Count); 
        for I := 0 to ListBox.Items.Count - 1 do 
        begin 
          INI.WriteString(ASection, 'Item' + IntToStr(I), ListBox.Items[I]); 
        end
      finally 
        INI.Free; 
      end
    end

    procedure INIToListBox(const AINIFile, ASection: string; ListBox: TListBox); 
    var 
      INI: TINIFile; 
      I, Count: Integer; 
    begin 
      INI := TINIFile.Create(AINIFile); 
      try 
        Count := INI.ReadInteger(ASection, 'Count', 0); 
        for I := 0 to Count - 1 do 
        begin 
          ListBox.Items.Add(INI.ReadString(ASection, 'Item' + IntToStr(I), '0')); 
        end
      finally 
        INI.Free; 
      end
    end

    {write ini} 
    procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      fName:='A'
      iniPath:=GetCurrentDir()+format('\%s.ini',[fName]); 
      ListBoxToINI(iniPath,'列表框1',ListBox1); 
    end

    {read ini} 
    procedure TForm1.Button2Click(Sender: TObject); 
    begin 
      fName:='A'
      iniPath:=GetCurrentDir()+format('\%s.ini',[fName]); 
      INIToListBox(iniPath,'列表框1',ListBox1); 
      memo1.Text:=iniPath; 
    end

    procedure TForm1.Button3Click(Sender: TObject); 
    begin 
     ListBox1.Items:=memo1.Lines; 
    end

    procedure TForm1.Button4Click(Sender: TObject); 
    begin 
      listbox1.Clear; 
    end

    end.




    附件列表

    • 相关阅读:
      MySQL与Redis结合方案
      Linux系统如何监控服务器硬件、操作系统、应用服务和业务
      【MySQL】MySQL复制之防崩溃从节点
      Linux系统vim编辑器换行至文件的行首及行尾操作
      Xtrabackup远程备份
      innodb_force_recovery参数分析
      Oracle异构平台迁移利器之XTTS(使用rman方式)
      ES6基础语法
      读郭老师推荐书籍--《原则》
      PhpStorm 的基本应用
    • 原文地址:https://www.cnblogs.com/xe2011/p/2526771.html
    Copyright © 2011-2022 走看看