提供你一个StringList的例子procedure TQueryF.PrintLandUser(Printing : boolean); function FormatStr(s : string; StrLength :integer):string; var Temp : string; i : integer; begin Temp := ''; try for i := 1 to StrLength do Temp := Temp +' '; for i:= 1 to Length(s) do Temp[(StrLength-Length(s))div 2 +i] := s[i]; Result := Temp; except Result := s; end; end;var PrintList : TStringList; i : integer; LinesCount : integer; PriUserID : string; f : TextFile; begin if Printing = False then if (not SaveDialog1.Execute) then Exit; PrintList := TStringList.Create; LinesCount := 0; if ListView3.Items.Count >0 then PriUserID := ListView3.Items[0].Caption else PriUserID := ''; i := 0; while i <= ListView3.Items.Count-1 do begin if LinesCount = 0 then begin PrintList.Add(' <'+ListView3.Items[i].Caption+':'+ ListView3.Items[i].SubItems.Strings[0]+ '>没归还图书清单'); Inc(LinesCount); PrintList.Add(' 打印时间:'+DateToStr(Date)); Inc(LinesCount); PrintList.Add(''); Inc(LinesCount); PrintList.Add(' 图书号 | 借出时间 | 持有时间/天 | 罚金/元 '); Inc(LinesCount); PrintList.Add('----------------------------------'); Inc(LinesCount); end; if PriUserID = ListView3.Items[i].Caption then begin PrintList.Add(FormatStr(ListView3.Items[i].SubItems.Strings[3],14)+'|'+ FormatStr(ListView3.Items[i].SubItems.Strings[4],16)+'|'+ FormatStr(ListView3.Items[i].SubItems.Strings[5],16)+'|'+ FormatStr(ListView3.Items[i].SubItems.Strings[7],16)); Inc(LinesCount); Inc(i); if LinesCount > PrintLinesCount then PrintList.Add(#12); end else begin PriUserID := ListView3.Items[i].Caption; PrintList.Add(''); PrintList.Add(' <'+ListView3.Items[i].Caption+':'+ ListView3.Items[i].SubItems.Strings[0]+ '>没归还图书清单'); Inc(LinesCount); PrintList.Add(' 打印时间:'+DateToStr(Date)); Inc(LinesCount); PrintList.Add(''); Inc(LinesCount); PrintList.Add(' 图书号 | 借出时间 | 持有时间/天 | 罚金/元 '); Inc(LinesCount); PrintList.Add('----------------------------------'); Inc(LinesCount); Inc(LinesCount);// := 0; end; end; if Printing = False then try PrintList.SaveToFile(SaveDialog1.FileName); except MessageDlg('不能创建打印文件'+SaveDialog1.FileName, mtError,[mbok],0); end; if Printing =True then begin AssignPrn(f); try Rewrite(f); for i := 0 to PrintList.Count-1 do Writeln(f,PrintList[i]); CloseFile(f); except MessageDlg('打印失败',mtError,[mbok],0); CloseFile(f); end; end; PrintList.Free;
先接受到一个memo中,然后 memo1.lines.savetoFile(c:\a.txt);
可以输出到 text 中去 怎么调出来? 调出那个文件的语句怎么写?呵呵偶 是菜鸟啊
我靠, var slst:TStringList; begin slst:=TStringList.Create; slst.LoadFromFile(你的路径);//能SaveToFile就要LOadFromFile end;
上面几位的就是正确方法
先读到一个STRINGLIST是一个捷径,可以直接SAVETOFILE的~~
var
Temp : string;
i : integer;
begin
Temp := '';
try
for i := 1 to StrLength do
Temp := Temp +' ';
for i:= 1 to Length(s) do
Temp[(StrLength-Length(s))div 2 +i] := s[i];
Result := Temp;
except
Result := s;
end;
end;var
PrintList : TStringList;
i : integer;
LinesCount : integer;
PriUserID : string;
f : TextFile;
begin
if Printing = False then
if (not SaveDialog1.Execute) then
Exit;
PrintList := TStringList.Create;
LinesCount := 0;
if ListView3.Items.Count >0 then
PriUserID := ListView3.Items[0].Caption
else PriUserID := '';
i := 0;
while i <= ListView3.Items.Count-1 do
begin
if LinesCount = 0 then
begin
PrintList.Add(' <'+ListView3.Items[i].Caption+':'+
ListView3.Items[i].SubItems.Strings[0]+
'>没归还图书清单');
Inc(LinesCount);
PrintList.Add(' 打印时间:'+DateToStr(Date));
Inc(LinesCount);
PrintList.Add('');
Inc(LinesCount);
PrintList.Add(' 图书号 | 借出时间 | 持有时间/天 | 罚金/元 ');
Inc(LinesCount);
PrintList.Add('----------------------------------');
Inc(LinesCount);
end;
if PriUserID = ListView3.Items[i].Caption then
begin
PrintList.Add(FormatStr(ListView3.Items[i].SubItems.Strings[3],14)+'|'+
FormatStr(ListView3.Items[i].SubItems.Strings[4],16)+'|'+
FormatStr(ListView3.Items[i].SubItems.Strings[5],16)+'|'+
FormatStr(ListView3.Items[i].SubItems.Strings[7],16));
Inc(LinesCount);
Inc(i);
if LinesCount > PrintLinesCount then
PrintList.Add(#12);
end
else begin
PriUserID := ListView3.Items[i].Caption;
PrintList.Add('');
PrintList.Add(' <'+ListView3.Items[i].Caption+':'+
ListView3.Items[i].SubItems.Strings[0]+
'>没归还图书清单');
Inc(LinesCount);
PrintList.Add(' 打印时间:'+DateToStr(Date));
Inc(LinesCount);
PrintList.Add('');
Inc(LinesCount);
PrintList.Add(' 图书号 | 借出时间 | 持有时间/天 | 罚金/元 ');
Inc(LinesCount);
PrintList.Add('----------------------------------');
Inc(LinesCount);
Inc(LinesCount);// := 0;
end;
end;
if Printing = False then
try
PrintList.SaveToFile(SaveDialog1.FileName);
except
MessageDlg('不能创建打印文件'+SaveDialog1.FileName,
mtError,[mbok],0);
end;
if Printing =True then
begin
AssignPrn(f);
try
Rewrite(f);
for i := 0 to PrintList.Count-1 do
Writeln(f,PrintList[i]);
CloseFile(f);
except
MessageDlg('打印失败',mtError,[mbok],0);
CloseFile(f);
end;
end;
PrintList.Free;
memo1.lines.savetoFile(c:\a.txt);
怎么调出来? 调出那个文件的语句怎么写?呵呵偶 是菜鸟啊
var slst:TStringList;
begin
slst:=TStringList.Create;
slst.LoadFromFile(你的路径);//能SaveToFile就要LOadFromFile
end;
我的意思是 我现在靠各位大哥的指导 知道了如何输出数据到text 中去了比如 输出到 c:\1.text 可是 我现在不希望 每次点击 输出那个按钮后 自己到 c:\ 目录 底下去找那个1.text 我希望直接 出来了这个text 就是调用 windows 的 notepad 显示文件一样
不知道我表达的清楚不?
uses ShellApi;ShellExecute(0, 'open','NOTEPAD', 'c:\1.txt', nil,SW_SHOW);