我的问题是这样的,从一个文件中读出头信息,以及数据,然后画出波形。procedure TForm1.OpenClick(Sender: TObject);
var
FileHandle:Integer;pHead:pFileHeadInfo;
pChInfo:array of pChanInfo;//根据pHead^.nChannels定义长度
pChPara:array of pChanPara;
pTB:pTimeBaseInfo;pData:Pointer;I:Integer;OffPack:LongInt;f:LongInt;arr:array[0..5803] of SmallInt;
brr:array[0..5803] of double;begin
if(OpenDialog1.Execute) then
FileHandle:=FileOpen(OpenDialog1.FileName,fmOpenRead);
if (FileHandle>0) then
begin
//读文件头
New(pHead);
FileRead(FileHandle,pHead^,sizeof(FileHeadInfo));
SetLength(pChInfo,pHead^.nChannels);
SetLength(pChPara,pHead^.nChannels);
for I:=0 to pHead^.nChannels-1 do
begin
New(pChInfo[I]);
FileRead(FileHandle,pChInfo[I]^,sizeof(ChanInfo));
end; FileRead(FileHandle,Offpack,sizeof(longInt)); new(pTB);
FileRead(FileHandle,pTB^,sizeof(TimeBaseInfo));
//SetLength(arr,pTB^.Length);
//SetLength(brr,pTB^.Length); for I:=0 to pHead^.nChannels-1 do
begin
New(pChPara[I]);
FileRead(FileHandle,pChPara[I]^,sizeof(ChanPara));
end;//读数据部分 GetMem(pData,pTB^.Length*sizeof(SmallInt)); f:=sizeof(SmallInt)*pTB^.Length; FileRead(FileHandle,pData^,f); CopyMemory(@arr,pData,f); for I:=0 to pTB^.Length-1 do
begin
brr[I]:=arr[I]*pChPara[0]^.Range*pChInfo[0]^.ChKc/32768.0+pChInfo[0]^.ChBase;
end;
//画曲线
Chart1.Series[0].AddArray(brr);
FreeMem(pData,pTB^.Length*sizeof(SmallInt));
Dispose(pTB);
Dispose(pHead);
FileClose(FileHandle);
end;
end;
当我的arr,brr定义成定长是可以用的,我想把arr,brr定义成动态数组,数据的长度根据pTB^.Length定义,怎么调试都不行?这里不能用动态数组吗?帮帮忙,我是新手,没有太高的报酬。
var
FileHandle:Integer;pHead:pFileHeadInfo;
pChInfo:array of pChanInfo;//根据pHead^.nChannels定义长度
pChPara:array of pChanPara;
pTB:pTimeBaseInfo;pData:Pointer;I:Integer;OffPack:LongInt;f:LongInt;arr:array[0..5803] of SmallInt;
brr:array[0..5803] of double;begin
if(OpenDialog1.Execute) then
FileHandle:=FileOpen(OpenDialog1.FileName,fmOpenRead);
if (FileHandle>0) then
begin
//读文件头
New(pHead);
FileRead(FileHandle,pHead^,sizeof(FileHeadInfo));
SetLength(pChInfo,pHead^.nChannels);
SetLength(pChPara,pHead^.nChannels);
for I:=0 to pHead^.nChannels-1 do
begin
New(pChInfo[I]);
FileRead(FileHandle,pChInfo[I]^,sizeof(ChanInfo));
end; FileRead(FileHandle,Offpack,sizeof(longInt)); new(pTB);
FileRead(FileHandle,pTB^,sizeof(TimeBaseInfo));
//SetLength(arr,pTB^.Length);
//SetLength(brr,pTB^.Length); for I:=0 to pHead^.nChannels-1 do
begin
New(pChPara[I]);
FileRead(FileHandle,pChPara[I]^,sizeof(ChanPara));
end;//读数据部分 GetMem(pData,pTB^.Length*sizeof(SmallInt)); f:=sizeof(SmallInt)*pTB^.Length; FileRead(FileHandle,pData^,f); CopyMemory(@arr,pData,f); for I:=0 to pTB^.Length-1 do
begin
brr[I]:=arr[I]*pChPara[0]^.Range*pChInfo[0]^.ChKc/32768.0+pChInfo[0]^.ChBase;
end;
//画曲线
Chart1.Series[0].AddArray(brr);
FreeMem(pData,pTB^.Length*sizeof(SmallInt));
Dispose(pTB);
Dispose(pHead);
FileClose(FileHandle);
end;
end;
当我的arr,brr定义成定长是可以用的,我想把arr,brr定义成动态数组,数据的长度根据pTB^.Length定义,怎么调试都不行?这里不能用动态数组吗?帮帮忙,我是新手,没有太高的报酬。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货