望解决temp1及其他问题
完整代码在附件中
以下是部分代码:
temp1:?; //array of TSt_SQL?;
spm:TParam;
deststr:TStringArray;
lh,cols:integer;
sqls:string;
//
NegNum,NegBegPos,NegEndPos: integer;
FstPosiQ,LastPosiQ:double;
DeltaQ:double;
FstPosiH,LastPosiH:double;
DeltaH:single;
//
InputX: array[0..10000] of integer;
InputY:doutputarray;
OldLn :array[0..1] of integer;
NewX :doutputarray;
NewY :doutputarray;
NewLn :array[0..1] of integer;
NewXDT:dDtarray;
//实际的待插入点之前的取点数
rLn:integer;
min:single;
LastQDT,LastHDT:TDateTime;
SwLlfxHQGraphFormInit; //初始化水位-流量过程线分析条件
InitCzStr:='';
//读水文站点信息
InitCzIndex:=-1;
//
sqls:='select rtuid,rtuname from wds.rtu where (rtutype=1 or rtutype=3) order by rtuid';
cols:=2;
strpcopy(spm.SqlStr,sqls);
try
lh:=1024; //0;
new(temp1); //temp1:=nil;
GetSqlInfo(spm,lh,pointer(temp1),false); //这个函数调用改成直接用SQL取数据!
if lh=0 then QHStanmCmb.ItemIndex:=-1
else begin
for row:=0 to lh-1 do begin
StringToArray(temp1[row].str,deststr,cols);
QHstanmCmb.Items.Add(deststr[0]+'--'+deststr[1]);
if deststr[0]=InitCzStr then InitCzIndex:=row;
end;
QHStanmCmb.ItemIndex:=InitCzIndex;
end; //end lh>0
except
end;
dispose(temp1); //这些均要修改!
//初始化分析条件并绘制初始流量过程线
if SwLlHasData=false then begin CzHFillData:=false;CzQFillData:=false;
end ;
else
begin
CzHFillData:=true;
CzQFillData:=true;
if not Assigned(WaitSQLForm) then
Application.CreateForm(TWaitSQLForm,WaitSQLForm);
WaitSQLForm.Show;
WaitSQLForm.Update;
// HQDs.First;
// rec:=HQDs.RecordCount;
rec:=RecFromSwLl;
//输入数组数据
InputX[0]:=0;
InputY[0]:=CzHLine[0];
rLn:=1;
//每个取点精确到10分钟
for row:=1 to rec-1 do begin
min:=(MinutesBetween(CzHDT[row],CzHDT[row-1])+1) div 10; //0.3, 0,
if min<1 then begin min:=0; continue; end; //丢掉10分钟以下的点
InputX[rln]:=InputX[rln-1]+Trunc(min)+1; //
InputY[rln]:=CzHLine[rln];
inc(rln);
end;
//出口rln为实际的输入点数
//OldLn[0]的值为记录数加1
OldLn[0]:=rln+1;
//
//调用插值函数
Zlfxshare.aospl2(InputX,InputY,OldLn,NewX,CzHLnArr,NewLn);
//对插值后的负值数据进行修正
i:=0;k:=0;
NegBegPos:=-1;NegEndPos:=-1;
while(i<NewLn[0]) do begin
k:=i;
while((k<NewLn[0]) and (CzHLnArr[k]>=0)) do inc(k);
if (k>=NewLn[0]) then break;
NegBegPos:=k; //CzQLnArr[k]<0
FstPosiH:=CzHLnArr[NegBegPos-1];
while((k<NewLn[0]) and (CzHLnArr[k]<0)) do inc(k);
if (k>=NewLn[0]) then begin //只有一个负值时
CzHLnArr[NegBegPos]:=CzHLnArr[NegBegPos-1]+CzHLnArr[NegBegPos+1];
break;
end;
NegEndPos:=k-1; // CzQLnArr[k]>0
LastPosiH:=CzHLnArr[NegEndPos+1];
NegNum:=NegEndPos-NegBegPos+1;
DeltaH:=(LastPosiH-FstPosiH)/(NegNum+1);
for j:=0 to NegNum-1 do
CzHLnArr[NegBegPos+j]:=FstPosiH+DeltaH*j;
i:=k; //loop i from k subposition
end; //end while
//对起始时间进行调整
CzInitDT:=CzHDT[0];
ModiStartDTToMi(CzInitDT,CzCurDT);
for i:=0 to NewLn[0]-1 do begin
// ALabel:=FormatDateTime('yyyy-mm-dd hh',HQDs.Fields[0].AsDateTime);
LastHDT:=CzCurDT+i/144;
if LastHDT>CzHDT[rec-1] then break;
SeriesH.AddXY(CzCurDT+i/144,CzHLnArr[i],'',SeriesH.SeriesColor);
// SeriesHP.AddXY(CzCurDT+i/144,CzHLnArr[i],'',SeriesHP.SeriesColor);
end;
//绘制流量过程线
//输入数组数据
InputX[0]:=0;
InputY[0]:=CzQLine[0];
rLn:=1;
//每个取点精确到10分钟
for row:=1 to rec-1 do begin
min:=(MinutesBetween(CzQDT[row],CzQDT[row-1])+1) div 10;
if min<1 then begin min:=0; continue; end; //丢掉10分钟以下的点
InputX[rln]:=InputX[rln-1]+Trunc(min)+1; //
InputY[rln]:=CzQLine[rln];
inc(rln);
end;
//出口rln为实际的输入点数
//OldLn[0]的值为记录数加1
OldLn[0]:=rln+1;
//
//调用插值函数
Zlfxshare.aospl2(InputX,InputY,OldLn,NewX,CzQLnArr,NewLn);
//对插值后的负值数据进行修正
i:=0;k:=0;
NegBegPos:=-1;NegEndPos:=-1;
while(i<NewLn[0]) do begin
k:=i;
while((k<NewLn[0]) and (CzQLnArr[k]>=0)) do inc(k);
if (k>=NewLn[0]) then break;
NegBegPos:=k; //CzQLnArr[k]<0
FstPosiQ:=CzQLnArr[NegBegPos-1];
while((k<NewLn[0]) and (CzQLnArr[k]<0)) do inc(k);
if (k>=NewLn[0]) then begin //只有一个负值时
CzQLnArr[NegBegPos]:=CzQLnArr[NegBegPos-1]+CzQLnArr[NegBegPos+1];
break;
end;
NegEndPos:=k-1; // CzQLnArr[k]>0
LastPosiQ:=CzQLnArr[NegEndPos+1];
NegNum:=NegEndPos-NegBegPos+1;
DeltaQ:=(LastPosiQ-FstPosiQ)/(NegNum+1);
for j:=0 to NegNum-1 do
CzQLnArr[NegBegPos+j]:=FstPosiQ+DeltaQ*j;
i:=k; //loop i from k subposition
end; //end while
//对起始时间进行调整
CzInitDT:=CzQDT[0];
ModiStartDTToMi(CzInitDT,CzCurDT);
for i:=0 to NewLn[0]-1 do begin
LastQDT:=CzCurDT+i/144;
if LastQDT>CzQDT[rec-1] then break;
SeriesQ.AddXY(CzCurDT+i/144,CzQLnArr[i],'',SeriesQ.SeriesColor);
// SeriesQP.AddXY(CzCurDT+i/144,CzQLnArr[i],'',SeriesQP.SeriesColor);
end;
//重绘水位和流量过程线
ReDispCzHQLine;
if (HChart.NumPages>1) or (QChart.NumPages>1) then begin
BitBtn1.Enabled:=true;BitBtn2.Enabled:=true;BitBtn3.Enabled:=true;BitBtn4.Enabled:=true;
end
else begin
BitBtn1.Enabled:=false;BitBtn2.Enabled:=false;BitBtn3.Enabled:=false;BitBtn4.Enabled:=false;
end;
BitBtn4Click(nil);
WaitSQLForm.Close;
end;//end else SwLlHasData=true
end;