L
laixbsh
Unregistered / Unconfirmed
GUEST, unregistred user!
//stgRoot全局变量
问题:在Button1Click中可以把数据流中的数据读上来,而在Button2Click
中却不能,这是什么问题呢?请帮忙看看,谢谢!
procedure TForm1.Button1Click(Sender: TObject);
type
datared=record
com:String;
dd:Integer;
end;
VAR
indata:array of datared;
outdata:array of datared;
stmData,outDatas:IStream;
os:tolestream;
instr,outstr:string;
bytewrite,byteread:longint;
begin
TRY
if StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot)=STG_E_FILENOTFOUND then
olecheck(stgCreateDocFile('d:/structfile/structdemo.ss',STGM_CREATE OR STGM_READWRITE
or STGM_SHARE_EXCLUSIVE ,0,stgRoot));
EXCEPT
END;
olecheck(stgRoot.CreateStream('computer',STGM_CREATE OR STGM_WRITE
or STGM_SHARE_EXCLUSIVE,0,0,outDatas));
setlength(indata,1);
indata[0].com:='com1';
indata[0].dd:=19600;
outDatas.Write(@indata,sizeof(indata),@bytewrite);
stgRoot:=nil;
StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot);
olecheck(stgRoot.OpenStream('computer',nil,STGM_READWRITE OR STGM_SHARE_EXCLUSIVE,0,stmData));
setlength(outdata,1);
stmData.read(@outdata,sizeof(outdata),@byteread);
//数据可以读出来
//这是outdata[0].com:='COM1';
end;
procedure TForm1.Button2Click(Sender: TObject);
type
datared=record
com:String;
dd:Integer;
end;
var
stmData:IStream;
outdata:array of datared;
os:tolestream;
byteread:integer;
begin
StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot);
olecheck(stgRoot.OpenStream('computer',nil,STGM_READWRITE OR STGM_SHARE_EXCLUSIVE,0,stmData));
setlength(outdata,1);
stmData.read(@outdata,sizeof(outdata),@byteread);
//数据读不出来,为什么呢?
// 这时outdata[0].com:='';
end;
当我把数据写完后退出程序,再启动程序时执行Button2Click也不行。
问题:在Button1Click中可以把数据流中的数据读上来,而在Button2Click
中却不能,这是什么问题呢?请帮忙看看,谢谢!
procedure TForm1.Button1Click(Sender: TObject);
type
datared=record
com:String;
dd:Integer;
end;
VAR
indata:array of datared;
outdata:array of datared;
stmData,outDatas:IStream;
os:tolestream;
instr,outstr:string;
bytewrite,byteread:longint;
begin
TRY
if StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot)=STG_E_FILENOTFOUND then
olecheck(stgCreateDocFile('d:/structfile/structdemo.ss',STGM_CREATE OR STGM_READWRITE
or STGM_SHARE_EXCLUSIVE ,0,stgRoot));
EXCEPT
END;
olecheck(stgRoot.CreateStream('computer',STGM_CREATE OR STGM_WRITE
or STGM_SHARE_EXCLUSIVE,0,0,outDatas));
setlength(indata,1);
indata[0].com:='com1';
indata[0].dd:=19600;
outDatas.Write(@indata,sizeof(indata),@bytewrite);
stgRoot:=nil;
StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot);
olecheck(stgRoot.OpenStream('computer',nil,STGM_READWRITE OR STGM_SHARE_EXCLUSIVE,0,stmData));
setlength(outdata,1);
stmData.read(@outdata,sizeof(outdata),@byteread);
//数据可以读出来
//这是outdata[0].com:='COM1';
end;
procedure TForm1.Button2Click(Sender: TObject);
type
datared=record
com:String;
dd:Integer;
end;
var
stmData:IStream;
outdata:array of datared;
os:tolestream;
byteread:integer;
begin
StgOpenStorage('d:/structfile/structdemo.ss',nil,STGM_READWRITE or STGM_SHARE_EXCLUSIVE,
NIL,0,stgRoot);
olecheck(stgRoot.OpenStream('computer',nil,STGM_READWRITE OR STGM_SHARE_EXCLUSIVE,0,stmData));
setlength(outdata,1);
stmData.read(@outdata,sizeof(outdata),@byteread);
//数据读不出来,为什么呢?
// 这时outdata[0].com:='';
end;
当我把数据写完后退出程序,再启动程序时执行Button2Click也不行。