怎样输出到一个文件中,保持StringGrid中的格式!(65分)

  • 主题发起人 coolingxyz
  • 开始时间
C

coolingxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
type
hist = Packed record
Id : string[10];
time : string[20];
style : string[16];
user : string[10];
comm : string[255];
end;


procedure TFrmhis.BitBtn4Click(Sender: TObject);
var
i : integer;
myHistory : Hist;
historyFile : TfileStream;
str : String[50];
begin
SaveDialog1.Title := '导出历史记录';
SaveDialog1.InitialDir := FrmFh.MyPath;
SaveDialog1.Filter := 'Data files (*.txt)|*.txt';
str :='';
str := '网络设备管理 历史记录 用户:' + FrmFh.LoginName + DateTimeToStr(now) + chr(13) ;
If SaveDialog1.Execute then
begin
if Pos('.txt',SaveDialog1.FileName) <= 0 then
SaveDialog1.FileName := SaveDialog1.FileName + '.txt';
historyFile := TFileStream.Create(SaveDialog1.FileName, fmCreate);
try
historyFile.Write(str, 255);
For i := 0 to StringGrid1.Row - 1 do
begin
if StringGrid1.Cells[0,i] = '' then continue;
myHistory.Id := StringGrid1.Cells[0,i]; //内容已经放在STringGrid1中了
myHistory.time := StringGrid1.Cells[1,i]; //StringGrid1的第一行是标题
myHistory.style := StringGrid1.Cells[2,i]; //也输出到文件中
myHistory.user := StringGrid1.Cells[3,i];
myHistory.comm := StringGrid1.Cells[4,i] + chr(13) ;
try
HistoryFile.Write(myHistory, SizeOf(Hist));
except
MessageDlg('文件读写错误。', mtError, [mbOk], 0);
Break;
end;
end;
finally
HistoryFile.Free;
end;
end;
end;

保存到文件后效果是这样的:(前面的 2 不知道是哪里来的???)

2中璞青创网络设备管理 历史记录 用户:admin2002-9-11 Id 时间 类型 用户 内容
9150 2002-9-11 19:19:15 停止广播 admin 用户停止UDP广播
9149 2002-9-11 19:19:13 用户登陆 admin 用户 admin 登陆





很杂乱,而且每一个字段的后面都出现了一个黑色的方块。我想让它能这样:
Id 时间 类型 用户 内容
9150 2002-9-11 19:19:15 停止广播 admin 用户停止UDP广播
9149 2002-9-11 19:19:13 用户登陆 admin 用户 admin 登陆

这样该怎么输出呢?
请大家指点。谢谢。
 
就是你将小黑方块都加进来了,导致什么都看不见了[:(]
自己看一下解决办法吧,可以搞定的。希望你使用了邮件通知。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1272381
 
顶部