P
pengd
Unregistered / Unconfirmed
GUEST, unregistred user!
TXS= Record
UWDM:string[20];
HLiuSH:string[24];
BSJ:Tdate;
HSBM:string[22];
BHSKR:string[9];
KRZHS:string[20];
SKR:string[100];
FKR:string[30];
FKRGBDM:string[3];
JSFS:string[12];
BZSRK:string[6];
SRKouble;
JEJHJEouble;
QTJEouble;
GJSZBM:string[200];
BHMYDWS:string[200];
TBR:string[100];
DHTB:String[20];
end;
PTXS=^TXS;
TXSManger=class
private
Stream:Tmemorystream;
public
count:integer;
conStructor Create() ;
Destructor Destroy;
procedure AppendOneRS(SWSJ:TXS);
procedure ReadOneRS(i:integer;PSWSJTXS);
procedure SaveToFile(FileName:string);
procedure LoadFromFile(Filename:string);
end;
implementation
constructor TXSManger.Create();
begin
stream:=TmemoryStream.Create;
stream.Position:=0;
count:=0;
end;
Destructor TXSManger.Destroy;
begin
stream.Free;
end;
procedure TXSManger.AppendOneXS(SWSJ:TXS);
begin
count:=count+1;
stream.Position:=(count-1)*sizeof(TXS);
stream.WriteBuffer(SWSJ,sizeof(TXS));
end;
procedure TXSManger.ReadOneRS(i:integer;PSWSJTXS);
begin
if i<=count then
begin
stream.Position:=(i-1)*sizeof(TXS);
stream.ReadBuffer(PSWSJ^,sizeof(TXS));
end;
end;
procedure TXSManger.SaveToFile(FileName:string);
var
ini:TIniFile;
newMs:TmemoryStream;
PSWSJTXS;
i:integer;
begin
Ini:=TIniFile.Create(Filename);
try
stream.Position:=0;
newMs:=TmemoryStream.Create;
new(PSWSJ);
newMs.SetSize(sizeof(TXS)*count);
newMs.Position:=0;
for i:=0 to count-1 do
begin
stream.ReadBuffer(PSWSJ^,sizeof(TXS));
newMs.WriteBuffer(PSWSJ^,sizeof(TXS));
end;
newMS.Position:=0;
showmessage(inttostr(newMs.size));
INI.WriteBinaryStream('MESSAGE','SWSRSZB',newMS);
finally
ini.Free;
stream.Free;
end;
end;
procedure TXSManger.LoadFromFile(Filename:string);
var
ini:TIniFile;
begin
Ini:=TIniFile.Create(Filename);
try
ini.ReadBinaryStream('MESSAGE','SWSRSZB',stream);
count:=stream.Size div sizeof(TXS);
stream.Position:=0;
finally
ini.Free;
end;
end;
TXS结构大约有700个字节的大小, 首先调用TXSManger.AppendOneXS(SWSJ:TXS)写入5条记录到流
,然后调用TXSManger.SaveToFile(FileName:string)保存到文件;当从文件读出数据的时候
只有第一,第二条记录的字段读出的值与写入一致,其他记录都是空的,没有数据,
请问高手是什么原因?写入记录的时候内存流溢出?Tmemorystream能写多少数据到文件中呢?Thanks!!!
UWDM:string[20];
HLiuSH:string[24];
BSJ:Tdate;
HSBM:string[22];
BHSKR:string[9];
KRZHS:string[20];
SKR:string[100];
FKR:string[30];
FKRGBDM:string[3];
JSFS:string[12];
BZSRK:string[6];
SRKouble;
JEJHJEouble;
QTJEouble;
GJSZBM:string[200];
BHMYDWS:string[200];
TBR:string[100];
DHTB:String[20];
end;
PTXS=^TXS;
TXSManger=class
private
Stream:Tmemorystream;
public
count:integer;
conStructor Create() ;
Destructor Destroy;
procedure AppendOneRS(SWSJ:TXS);
procedure ReadOneRS(i:integer;PSWSJTXS);
procedure SaveToFile(FileName:string);
procedure LoadFromFile(Filename:string);
end;
implementation
constructor TXSManger.Create();
begin
stream:=TmemoryStream.Create;
stream.Position:=0;
count:=0;
end;
Destructor TXSManger.Destroy;
begin
stream.Free;
end;
procedure TXSManger.AppendOneXS(SWSJ:TXS);
begin
count:=count+1;
stream.Position:=(count-1)*sizeof(TXS);
stream.WriteBuffer(SWSJ,sizeof(TXS));
end;
procedure TXSManger.ReadOneRS(i:integer;PSWSJTXS);
begin
if i<=count then
begin
stream.Position:=(i-1)*sizeof(TXS);
stream.ReadBuffer(PSWSJ^,sizeof(TXS));
end;
end;
procedure TXSManger.SaveToFile(FileName:string);
var
ini:TIniFile;
newMs:TmemoryStream;
PSWSJTXS;
i:integer;
begin
Ini:=TIniFile.Create(Filename);
try
stream.Position:=0;
newMs:=TmemoryStream.Create;
new(PSWSJ);
newMs.SetSize(sizeof(TXS)*count);
newMs.Position:=0;
for i:=0 to count-1 do
begin
stream.ReadBuffer(PSWSJ^,sizeof(TXS));
newMs.WriteBuffer(PSWSJ^,sizeof(TXS));
end;
newMS.Position:=0;
showmessage(inttostr(newMs.size));
INI.WriteBinaryStream('MESSAGE','SWSRSZB',newMS);
finally
ini.Free;
stream.Free;
end;
end;
procedure TXSManger.LoadFromFile(Filename:string);
var
ini:TIniFile;
begin
Ini:=TIniFile.Create(Filename);
try
ini.ReadBinaryStream('MESSAGE','SWSRSZB',stream);
count:=stream.Size div sizeof(TXS);
stream.Position:=0;
finally
ini.Free;
end;
end;
TXS结构大约有700个字节的大小, 首先调用TXSManger.AppendOneXS(SWSJ:TXS)写入5条记录到流
,然后调用TXSManger.SaveToFile(FileName:string)保存到文件;当从文件读出数据的时候
只有第一,第二条记录的字段读出的值与写入一致,其他记录都是空的,没有数据,
请问高手是什么原因?写入记录的时候内存流溢出?Tmemorystream能写多少数据到文件中呢?Thanks!!!