我在form上放了一个edit框,另外有一个my.ini文件,里面的文本比如如下:
 
                      你好!欢迎!
                      hello,welcome
                      thankyou
                      nice
在这个from的OnCreate事件中,请问用哪个函数可以把任意的字符(比如thankyou)显示在edit框中。谢谢!!!!
另外,当我改动edit框中的内容后(例如该成了 thanks),按一个button键后,可以把修改后的字符保存到文件中响应的地方。

解决方案 »

  1.   

    那你就读写 ini呗
    类是TiniFile,看帮助就知道怎么用了;
    读是:
    var
    ini:TiniFile;
    begin
    ini := TiniFile.create('c:\my.ini');
    edit1.text := ini.readstring('section','key','');
    ini.free;
    end;
    写是
    var
    ini:TiniFile;
    begin
    ini := TiniFile.create('c:\my.ini');
    ini.writestring('section','key',edit1.text);
    ini.free;
    end;
    但是的要求你的文件的符合ini文件的格式[section]
    key="thank you"
    ....
    [..]
    key2=".."
    ....
      

  2.   

    uses inifiles;                         //使用ini单元文件
    var
      Form1: TForm1;
      inifile: TIniFile;implementation{$R *.dfm}
    procedure TForm1.Button1Click(Sender: TObject);    //读按钮代码
    begin
      showMessage(IniFile.ReadString('set','set', ''));
    end;
    procedure TForm1.Button2Click(Sender: TObject);    //写按钮代码
    begin
        IniFile.WriteString('set', 'set', edit1.Text);
    end;
    procedure TForm1.FormCreate(Sender: TObject);     //初始化生成ini文件
    begin
        IniFile := TIniFile.Create('c:\demo.ini');
    end;
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);//释放资源
    begin
       iniFile.Free;
    end;end.生成的ini文件符合自己的格式,关于这点你看有关ini的资料:[set]
    set=hellodelphi6+win2000下调试通过
      

  3.   

    我看你的INI文件格式就不标准 所以只能使用文本方式读取
    function GetInfo(file:String;Line:Integer):String;
    var
      tmpT: TextFile;
      lsLine: String;
      i   : Integer;
    begin  
      try
        AssignFile(tmpT,file);
        Reset(tmpT);
      except
        Result := '';
        exit;
      end;
      i := 0;
      while (not Eof(tmpT)) and (i<>Line) do
      begin 
        Inc(i);
        ReadLn(tmpT,lsLine);
      end;
      Result := lsLine;
      CloseFile(tmpT);
    end;