我想要读取一个模板文件.比如*.tmp(其实就是TXT文本)里面有一个特殊字符串
例如:`查询结果`
要怎么样读到这个位置.然后把其他的一个变量,(例:r)插入到这个地方.高手指教

解决方案 »

  1.   

    用xml或者ini文件可能更方便点
      

  2.   

    我把我的代码表出来好了.大家看下下.
    var
       iFileHandle:integer;
       iFileLength:integer;
       iBytesRead: Integer;
       Buffer: PChar;
       i: Integer;
       S:string;
    begin 
    iFileHandle:=FileOpen('E:\DLL\webdna\templates\result.tmp',fmOpenReadWrite);   //文件可读也可写fmOpenReadWrite
       if iFileHandle > 0 then        //读取文件是否存在
         begin
           //修改模板文件
           try
             iFileLength := FileSeek(iFileHandle,0,2);  //0文件头部.2文件尾部
             FileSeek(iFileHandle,0,0);
             Buffer := PChar(AllocMem(iFileLength+1));
             iBytesRead := FileRead(iFileHandle,Buffer,iFileLength);
             FileClose(iFileHandle);        //`查询结果`
             //S为模板文件中的字符要怎么得到.
             
               while Pos('`查询结果`',S) >0 do
                insert(r,S,Pos('`查询结果`',S));
           finally
             FreeMem(Buffer);
           end;
         end;