具体看代码
 var
  i : integer;
  aStrList : TStringList;
begin
  aStrList := TStringList.create;
  for i:= 0 to 10 do begin
  aStrList.add(inttostr(i));
  aStrList.SaveToFile('c:\1.txt');
  end;
end;我可能没说清楚,我说的是最后的那个回车符大家可以看看保存的文本里面第12行是空的,怎么不要

解决方案 »

  1.   

    Trim 清空,还有就是不要用 aStrList.SaveToFile('c:\1.txt');这种方式保存
    想想就能解决
    s:=TrimRight(aStrList.Text);
    ..
    WriteFile(hFile,s[1],Length(s), BytesWrite, nil);
      

  2.   

    不行,还是解决不了,用WriteFile(hFile,s[1],Length(s), BytesWrite, nil);基本上整个程序都要改动,太大了,还有没有其他办法啊
      

  3.   

    可以修改TStringList的源码可以达到目的,修改可参考以下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
      cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, DB,
      cxDBData, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
      ADODB, cxGridLevel, cxClasses, cxGridCustomView, cxGrid, StdCtrls;type
      TStringList = class(Classes.TStringList)
      private
        function _GetText:string;
      public
        procedure SaveToFile(const FileName: string); override;
      end;  TForm1 = class(TForm)
        Button_1: TButton;
        procedure Button_1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button_1Click(Sender: TObject);
    var
      v:TStringList;
      i:Integer;
    begin
      v := TStringList.Create;
      try
        for i:=0 to 20 do
          v.Add(IntToStr(i));
        v.SaveToFile('d:\1.txt');
      finally
        v.Free;
      end;
    end;{ TStringList }function TStringList._GetText: string;
    var
      I, L, Size, Count: Integer;
      P: PChar;
      S, LB: string;
    begin
      Count := GetCount;
      Size := 0;
      LB := sLineBreak;
      for I := 0 to Count - 1 do Inc(Size, Length(Get(I)));
      Size := Size + Length(LB)* (Count -1);
      SetString(Result, nil, Size);
      P := Pointer(Result);
      for I := 0 to Count - 1 do
      begin
        S := Get(I);
        L := Length(S);
        if L <> 0 then
        begin
          System.Move(Pointer(S)^, P^, L);
          Inc(P, L);
        end;
        L := Length(LB);
        if (L <> 0) and (I <> Count -1 ) then
        begin
          System.Move(Pointer(LB)^, P^, L);
          Inc(P, L);
        end;
      end;
    end;procedure TStringList.SaveToFile(const FileName: string);
    var
      S: string;
      vStream:TStream;
    begin
      vStream := TFileStream.Create(FileName, fmCreate);
      try
        S := _GetText;
        vStream.WriteBuffer(Pointer(S)^, Length(S));
      finally
        vStream.Free;
      end;
    end;end.
      

  4.   

    我觉得还是写一个stringlist的子类吧
      

  5.   


    这样当然也可以!但是楼主得改动小部份代码!如果把上面贴出来的代码单独放在一个单元中!只要在使用到TStringList并且有这样的需求的地方引用一下该单元就可以啦!可以不改其它代码,这样是不是方便一点呢?仅供参考!谢谢!
      

  6.   

    TStrings保存是这样的,提供思路:
    1.改源码
    2.改用其它方法保存
    3.保存后,打开文件把回车换行去掉重新保存
    4.保留它,只是使用时读取后,再把回车换行去掉
      

  7.   

    这样同样也需要修改源码,除非你不使用classes单元中的其他类6楼说的好,我一般选择近似第4种的做法,在使用时过滤掉空行