当读写单个记录时一切正常,但是如果有多个记录时可写,但读不正常,不是出来乱码就是无法执行PTkCost=^TkCost;
Tkcost=packed Record
kName:string; //名称
kinv1, //单价金额
kinv2,//数量
kinv3,//合价
kinv4:real; //属性
kinvFF:string;
end;
-----
---var
Form1: TForm1;klist:tlist;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
var n:integer;ww:string;wwfile:tfilestream;fcost:Tkcost;
begin
if savedialog1.Execute then
begin
ww:=savedialog1.FileName;
wwfile:=tfilestream.Create(ww,fmCreate or fmOpenReadWrite);
for n:=1 to 5 do
begin
fcost.kName:='奇奇怪怪'+inttostr(n);
fcost.kinv1:=-0.11*n;
fcost.kinv2:=22;
fcost.kinv3:=5588;
fcost.kinv4:=0;
fcost.kinvFF:='ABCr';
wwfile.Write(fcost,sizeof(fcost));
end;
wwfile.Free;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var n:integer;ww:string;wwfile:tfilestream;fcost3,fcost2:ptkcost;fcost:Tkcost;
begin
if opendialog1.Execute then
begin
klist.Clear;
ww:=opendialog1.FileName;
wwfile:=tfilestream.Create(ww,fmOpenRead);
for n:=1 to 5 do begin
wwfile.Read(fcost,sizeof(fcost)) ;
new(fcost3);
fcost3.kName:=fcost.kName;
fcost3.kinv1:=fcost.kinv1;
fcost3.kinv2:=fcost.kinv2;
fcost3.kinv3:=fcost.kinv3;
fcost3.kinv4:=fcost.kinv4;
fcost3.kinvFF:=fcost.kinvFF;
klist.Add(fcost3);
end;
for n:=1 to 5 do
begin
fcost2:=klist.Items[n-1];
stringgrid1.Cells[n,1]:=fcost2.kName;
stringgrid1.Cells[n,2]:=fcost2.kinvFF;
end;
wwfile.Free;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
klist:=tlist.Create;
end;
Tkcost=packed Record
kName:string; //名称
kinv1, //单价金额
kinv2,//数量
kinv3,//合价
kinv4:real; //属性
kinvFF:string;
end;
-----
---var
Form1: TForm1;klist:tlist;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
var n:integer;ww:string;wwfile:tfilestream;fcost:Tkcost;
begin
if savedialog1.Execute then
begin
ww:=savedialog1.FileName;
wwfile:=tfilestream.Create(ww,fmCreate or fmOpenReadWrite);
for n:=1 to 5 do
begin
fcost.kName:='奇奇怪怪'+inttostr(n);
fcost.kinv1:=-0.11*n;
fcost.kinv2:=22;
fcost.kinv3:=5588;
fcost.kinv4:=0;
fcost.kinvFF:='ABCr';
wwfile.Write(fcost,sizeof(fcost));
end;
wwfile.Free;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var n:integer;ww:string;wwfile:tfilestream;fcost3,fcost2:ptkcost;fcost:Tkcost;
begin
if opendialog1.Execute then
begin
klist.Clear;
ww:=opendialog1.FileName;
wwfile:=tfilestream.Create(ww,fmOpenRead);
for n:=1 to 5 do begin
wwfile.Read(fcost,sizeof(fcost)) ;
new(fcost3);
fcost3.kName:=fcost.kName;
fcost3.kinv1:=fcost.kinv1;
fcost3.kinv2:=fcost.kinv2;
fcost3.kinv3:=fcost.kinv3;
fcost3.kinv4:=fcost.kinv4;
fcost3.kinvFF:=fcost.kinvFF;
klist.Add(fcost3);
end;
for n:=1 to 5 do
begin
fcost2:=klist.Items[n-1];
stringgrid1.Cells[n,1]:=fcost2.kName;
stringgrid1.Cells[n,2]:=fcost2.kinvFF;
end;
wwfile.Free;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
klist:=tlist.Create;
end;
解决方案 »
- 如何在delphi7中dbgrid中使用键盘上的方向键
- 网络掉线后更新问题
- 请教遍历TQuery中数据的快速方法!谢谢!
- Delphi7目录结构----初学者参考
- 请问有关打印报表的控件问题
- 用TQUERY删除数据后,在提交数据时说数据集状态不可编辑,如何修改TQUER才能行呀
- 过滤Filtered使用like怎么失败
- 谁有比较cool的编辑界面的第三方控件,发个给我,给分100。[email protected]
- 谁知道Delphi的名字是怎么来的?有什么技术内幕?
- 请问怎么从一个程序查找traybar中的图标及他们所属的程序或窗口?然后关闭或显示这些图标。
- 高分高M求:使用eReport开发报表
- 哪有感知日期时间的数据库控件?
wwfile.Read(fcost,sizeof(fcost)) ;
new(fcost3);
fcost3.kName:=fcost.kName;
fcost3.kinv1:=fcost.kinv1;
fcost3.kinv2:=fcost.kinv2;
fcost3.kinv3:=fcost.kinv3;
fcost3.kinv4:=fcost.kinv4;
fcost3.kinvFF:=fcost.kinvFF;
klist.Add(fcost3);
这个地方,你每循环一次,都new(fcost3),这里可能有问题
string没有指定长度,也就是说格式长度不统一,怎么读呀
可以这样定义 kName:array[100] of char;