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.




    附件列表

    • 相关阅读:
      Tomcat 调优的技巧
      双亲委派模型
      字典树实现
      Python获取房价信息和导出EXCEL
      日志检索关键字并截取上下行关联内容
      GC日志分析
      Linux 查看 删除进程
      Rotate partitions in DB2 on z
      C++ STL string
      DB2 for z: system catalog tables
    • 原文地址:https://www.cnblogs.com/xe2011/p/2526771.html
    Copyright © 2011-2022 走看看