procedure TForm1.ReadData(s_count:integer; mid,tname:String);
var
F: TextFile;
St: String;
mydate,myTime : TDateTime;
//TmpList: TStringList;
TmpList: TStrings;
i,j ,first, num : integer;
value,disp,asum,change : array of real;
ssum : real;
//degree,length,temp,x,y,z,db,radians : array of real;
direc,direc2,tablepath,tablename,cPath:string;
simpleX,simpleY, rt_disp, beunhoungule : real;
begin
SetLength(value , s_count);
SetLength(disp , s_count);
SetLength(asum , s_count);
SetLength(change , s_count);
St:=''; i:=0; first := 0;
if FileExists(inpath1) then
begin
GetDir(0,direc);
if DirectoryExists(outpath1) and (direc <> outpath1) then ChDir(direc)
else if not DirectoryExists(outpath1) then
begin
MkDir(outpath1);
ChDir(outpath1);
end;
GetDir(0,direc2);
cPath := direc2 + '\DataFile1.dat';
if FileExists(cPath) then DeleteFile(cPath);
CopyFile1(inpath1,cPath); //IO error 방지위해 원본복사
if Table1.Active then Table1.Close;
Table1.DisableControls;
Table1.Databasename := outpath1;
Table1.Tablename := tname; //'tb_incline_' + mid + '.db'
Table1.Open;
if Table8.Active then Table8.Close;
Table8.DisableControls; //경고table의 마지막 날짜 가져오기
Table8.Databasename := outpath1;
Table8.Tablename := 'tb_Alarm_' + mid + '.db'; //tb_alarm_tpms_mid.db 에서 바꿈
Table8.Open;
if not Table8.Eof then Table8.Last;
tablepath := ExtractFilePath(inpath1);
tablename := ExtractFileName(inpath1);
ChDir(tablepath);
GetDir(0,direc);
{$I-}
AssignFile(F, inpath1);
Reset(F);
if Table1.Eof then first := 1
else begin
first := 0;
end;
try
while not Eof(F) do
begin
Readln(F,St);
TmpList := TStringList.Create;
TmpList.CommaText := St;
i:=TmpList.Count;
year := TmpList[1];
date := TmpList[2];
time := TmpList[3];
ssum := 0;
for i:=0 to s_count-1 do
begin
value[i] := StrToFloat(TmpList[a_col[i]-1]);
disp[i] := Sin(3.14159/180*
( a_factor_a[i]
+a_factor_b[i]*value[i]
+a_factor_c[i]*Power(value[i],2)
+a_factor_d[i]*Power(value[i],3)
+a_factor_e[i]*Power(value[i],4)
+a_factor_f[i]*Power(value[i],5)
)
) * a_length[i];
ssum := ssum + disp[i];
end;
CalcDate(year, date, time, myDate,myTime);
//계측일
///////////////////////////////////
if (myDate>lastDate) or ((myDate=lastDate)and(myTime>lastTime))
or (myDate+myTime>lastDate+lastTime) then
begin
if (myDate+myTime>InitDate+InitTime) or(myDate+myTime=InitDate+InitTime) or (InitDate+InitTime=0) then
begin
asum[s_count-1] := ssum;
for i:=s_count-2 downto 0 do begin
asum[i] := ssum - disp[i+1];
end;
for j:=0 to s_count do
begin
if (j<s_count) then begin
Table1.Insert;
Table1['Date'] := mydate;
Table1['Time'] := myTime;
Table1['DateTime'] := mydate + myTime;
Table1['DateTime2'] := simpleDate + ' ' + simpleTime;
if j=0 then Table1['Depth'] := 0
else Table1['Depth'] := depth[j-1];
Table1['Value'] := value[j];
Table1['Disp'] := SimpleRoundTo(disp[j],-3);
Table1['Sum'] := SimpleRoundTo(asum[j] ,-3);
change[j] := asum[j] - isum[j];
Table1['Change'] := SimpleRoundTo(change[j],-3);
end else begin
Table1.Insert;
Table1['Date'] := mydate;
Table1['Time'] := myTime;
Table1['DateTime'] := mydate + myTime;
Table1['DateTime2'] := simpleDate + ' ' + simpleTime;
Table1['Depth'] := depth[j-1];
Table1['Value'] := value[j-1];
Table1['Disp'] := SimpleRoundTo(disp[j-1],-3);
Table1['Sum'] := SimpleRoundTo(asum[j-1] ,-3);
change[j] := asum[j-1] - isum[j-1];
Table1['Change'] := SimpleRoundTo(change[j-1],-3);
end;
//////////////////////////////
if (lastalarmdate < Table1.FieldByName('DateTime2').AsString) and (alarm_ok) then
begin
if (alarm_ok) and (Abs(Table1.FieldByName('Change').AsFloat)>limit/warn_k1) then
begin
alarm_cnt1[j] := alarm_cnt1[j] + 1;
if (ntrigger<=alarm_cnt1[j]) then
begin
Table8.Insert;
Table8['계측일시'] := Table1['DateTime2'];
Table8['Kind'] := '경사계';
Table8['경고계측기'] := '경사계 : ' + Label_mname.Caption + 'Depth:'+FloatToStr(depth[j]);
Table8['경고내역'] := '경사계관리기준치 '+ FloatToStr(limit/warn_k1)+ '을'+IntToStr(alarm_cnt1[j])+'번 벗어남';
Table8.Post;
write_ok := 1; alarm_cnt1[j] := 0;
//SendSms('TPMS', warn_k2, alarm_cnt2[j]);
end else begin
if write_ok=1 then begin alarm_cnt1[j] := 0; write_ok:= 0; end;
end;
end;
end;
//////////////////////////////
end;
Table1.Post;
lastTime := mytime; lastDate := myDate;
if myTime=0 then lastTime := 0;
TmpList.Free;
end;
end;
end;
//CloseFile(F);
//{$I+}
finally
CloseFile(F); <------ 이곳에서 에러가 납니다.
{$I+}
end;
// TmpList.Free;
end;
end;
표시한 부분에서에러창이 뜹니다. 캡쳐해서 파일첨부합니다. 급한데 어찌할지....
배열크기는 SetLength(value , s_count); 로 정해놓고
for 문은 scount+1 만큼 돌리니 그럴 수 밖에.... 창피하네요.