问题是这样的:
我有一个apache的配置文件,要做安装程序,需要修改里面的几个路径,配置文件的样式如下:
------------------------------------------------------------------------------
#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "D:/Apache2"
# configure the path to php.ini
PHPIniDir_STR   LOAD_APACHE_DLL_DWEISUN
   AddType application/x-httpd-php .php
----------------------------------------------------------------------------
问题是这样的:
我想要首先读取这个文件的内容,然后将第六行,也就是ServerRoot "D:/Apache2"替换成一个特定的路径如:d:/qbdsoft,同样,将第八行、第10行PHPIniDir_STR,LOAD_APACHE_DLL_DWEISUN也替换成一个指定的值。我指定的这几行的行数是固定的。
我刚开始接触delphi,请各位高手多多指教。

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var s:TStringList;
    begin
        s:=TStringList.Create;
        s.LoadFromFile('C:\1.txt');
        s.Strings[5]:='d:/qbdsoft';//第六行
        s.Strings[7]:='PHPIniDir_STR';
        ...
        s.SaveToFile('C:\1.txt');
        s.Free;
    end;
      

  2.   

    用TStringList的LoadFromFile然後用Strings[]下標是從零開始的.
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var s:TStringList;
    begin
        s:=TStringList.Create;
        try
          s.LoadFromFile('C:\1.txt');
          s.Strings[5]:='d:/qbdsoft';//第六行
          s.Strings[7]:='PHPIniDir_STR';
        ...
        finally
          s.SaveToFile('C:\1.txt');
          s.Free;
        end;
    end;