具体看代码
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行是空的,怎么不要
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行是空的,怎么不要
解决方案 »
- inforpower的控件TwwDBLookupCombo的使用方法?
- 做一个销售库存管理,最多30个客户端(分店),用什么方案好?
- 如何识别不同类别中的相同定义
- 怎么用adoquery往表里添加数据并即时更新表啊》
- 请问有无哪种label控件可以把字符做成艺术字体,我原来是在word中做好艺术字体,做成jpg文件,用image控件load该图片后,发现没法去掉白色
- 如何这般向网页提交内容
- 我的程序在别人的机器上运行不到
- 初学者,高分相送。如何调用 ShellExecute API 函数。
- 急!DELPHI创建的ACTIVEX-DLL,为什么用CreateOleObject之后调用方法出错?(VB,Jscrip也是如此)
- 把一个字符串中的字母大写转为小写最好的办法用什么
- 一段excel表导入到数据库的代码。
- 求助HTTP post方式发送xml文档
想想就能解决
s:=TrimRight(aStrList.Text);
..
WriteFile(hFile,s[1],Length(s), BytesWrite, nil);
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.
这样当然也可以!但是楼主得改动小部份代码!如果把上面贴出来的代码单独放在一个单元中!只要在使用到TStringList并且有这样的需求的地方引用一下该单元就可以啦!可以不改其它代码,这样是不是方便一点呢?仅供参考!谢谢!
1.改源码
2.改用其它方法保存
3.保存后,打开文件把回车换行去掉重新保存
4.保留它,只是使用时读取后,再把回车换行去掉