unit dianli;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, StdCtrls, TeEngine, Series, TeeProcs, Chart,Math,
ToolWin, ComCtrls;type
TForm1 = class(TForm)
Chart1: TChart;
Series_Liu: TLineSeries;
Series_Ge: TLineSeries;
Series_Da: TLineSeries;
Series_Qin: TLineSeries;
Label1: TLabel;
Lb_C: TLabel;
SpeedButton_P: TSpeedButton;
SpeedButton_Q: TSpeedButton;
SpeedButton_S: TSpeedButton;
SpeedButton_R: TSpeedButton;
Label2: TLabel;
Label3: TLabel;
Panel1: TPanel;
Timer1: TTimer;
CoolBar1: TCoolBar;
procedure FormCreate(Sender: TObject);
procedure SpeedButton_PClick(Sender: TObject);
procedure SpeedButton_QClick(Sender: TObject);
procedure SpeedButton_SClick(Sender: TObject);
procedure SpeedButton_RClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
PowerArray=array[0..59] of single;
var
Form1: TForm1;
temp1,temp2:integer;
LiuP,GeP,DaP,QinP,LiuQ,GeQ,DaQ,QinQ,LiuS,GeS,DaS,QinS,LiuR,
GeR,DaR,QinR:PowerArray;
SeriesNo:integer;
index:integer;
PowerNo:integer;
const
PLEVEL=15;
QLEVEL=15;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
SeriesNo:=1;
Timer1.Enabled:=false;
end;procedure TForm1.SpeedButton_PClick(Sender: TObject);
begin
SeriesNo:=1;
end;procedure TForm1.SpeedButton_QClick(Sender: TObject);
begin
SeriesNo:=2;
end;procedure TForm1.SpeedButton_SClick(Sender: TObject);
begin
SeriesNo:=3;
end;procedure TForm1.SpeedButton_RClick(Sender: TObject);
begin
SeriesNo:=4;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
i:integer;
begin
for i:=1 to 59 do
begin
LiuP[60-i]:=LiuP[60-i-1];
GeP[60-i]:=GeP[60-i-1];
DaP[60-i]:=DaP[60-i-1];
QinP[60-i]:=QinP[60-i-1]; LiuQ[60-i]:=LiuP[60-i-1];
GeQ[60-i]:=GeQ[60-i-1];
DaQ[60-i]:=DaQ[60-i-1];
QinQ[60-i]:=QinQ[60-i-1]; LiuS[60-i]:=Lius[60-i-1];
GeS[60-i]:=Ges[60-i-1];
DaS[60-i]:=Das[60-i-1];
QinS[60-i]:=Qins[60-i-1]; LiuR[60-i]:=LiuR[60-i-1];
GeR[60-i]:=GeR[60-i-1];
DaR[60-i]:=DaR[60-i-1];
QinR[60-i]:=QinR[60-i-1];
end;
LiuP[0]:=PLEVEL+random(100)/25;
GeP[0]:=PLEVEL+random(100)/25;
DaP[0]:=PLEVEL+random(100)/25;
QinP[0]:=PLEVEL+random(100)/25; LiuQ[0]:=QLEVEL+random(100)/10;
GeQ[0]:=QLEVEL+random(100)/10;
DaQ[0]:=QLEVEL+random(100)/10;
QinQ[0]:=QLEVEL+random(100)/10; LiuS[0]:=Sqrt(LiuP[0]*LiuP[0]+LiuQ[0]*LiuQ[0]);
GeS[0]:=Sqrt(GeS[0]*GeS[0]+GeS[0]*GeS[0]);
DaS[0]:=Sqrt(DaS[0]*DaS[0]+DaS[0]*DaS[0]);
QinS[0]:=Sqrt(QinS[0]*QinS[0]+QinS[0]*QinS[0]); LiuR[0]:=LiuP[0]/LiuS[0];
GeR[0]:=GeP[0]/GeS[0];
DaR[0]:=DaP[0]/DaS[0];
QinR[0]:=QinP[0]/QinS[0]; Series_Liu.Clear;
Series_Ge.Clear;
Series_Da.Clear;
Series_Qin.Clear; for i:=0 to 59 do
begin
case SeriesNo of
1:
begin
Chart1.LeftAxis.Maximum:=20;
Chart1.LeftAxis.Title.Caption:='有功功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时有功功率曲线');
Series_Liu.AddXY(i,LiuP[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeP[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaP[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinP[i],IntToStr(i),clyellow);
end;
2:
begin
Chart1.LeftAxis.Maximum:=8;
Chart1.LeftAxis.Title.Caption:='无功功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时无功功率曲线');
Series_Liu.AddXY(i,LiuQ[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeQ[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaQ[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinQ[i],IntToStr(i),clyellow);
end;
3:
begin
Chart1.LeftAxis.Maximum:=25;
Chart1.LeftAxis.Title.Caption:='视在功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时视在功率曲线');
Series_Liu.AddXY(i,LiuS[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeS[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaS[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinS[i],IntToStr(i),clyellow);
end;
4:
begin
Chart1.LeftAxis.Maximum:=1;
Chart1.LeftAxis.Title.Caption:='功率因数(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时功率因数曲线');
Series_Liu.AddXY(i,LiuR[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeR[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaR[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinR[i],IntToStr(i),clyellow);
end;
end;
end;
end;end.上述代码为一用数组和TCHART来显示不同情况下的数据曲线图,但为什么,显示不出来呢?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, StdCtrls, TeEngine, Series, TeeProcs, Chart,Math,
ToolWin, ComCtrls;type
TForm1 = class(TForm)
Chart1: TChart;
Series_Liu: TLineSeries;
Series_Ge: TLineSeries;
Series_Da: TLineSeries;
Series_Qin: TLineSeries;
Label1: TLabel;
Lb_C: TLabel;
SpeedButton_P: TSpeedButton;
SpeedButton_Q: TSpeedButton;
SpeedButton_S: TSpeedButton;
SpeedButton_R: TSpeedButton;
Label2: TLabel;
Label3: TLabel;
Panel1: TPanel;
Timer1: TTimer;
CoolBar1: TCoolBar;
procedure FormCreate(Sender: TObject);
procedure SpeedButton_PClick(Sender: TObject);
procedure SpeedButton_QClick(Sender: TObject);
procedure SpeedButton_SClick(Sender: TObject);
procedure SpeedButton_RClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
PowerArray=array[0..59] of single;
var
Form1: TForm1;
temp1,temp2:integer;
LiuP,GeP,DaP,QinP,LiuQ,GeQ,DaQ,QinQ,LiuS,GeS,DaS,QinS,LiuR,
GeR,DaR,QinR:PowerArray;
SeriesNo:integer;
index:integer;
PowerNo:integer;
const
PLEVEL=15;
QLEVEL=15;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
SeriesNo:=1;
Timer1.Enabled:=false;
end;procedure TForm1.SpeedButton_PClick(Sender: TObject);
begin
SeriesNo:=1;
end;procedure TForm1.SpeedButton_QClick(Sender: TObject);
begin
SeriesNo:=2;
end;procedure TForm1.SpeedButton_SClick(Sender: TObject);
begin
SeriesNo:=3;
end;procedure TForm1.SpeedButton_RClick(Sender: TObject);
begin
SeriesNo:=4;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
i:integer;
begin
for i:=1 to 59 do
begin
LiuP[60-i]:=LiuP[60-i-1];
GeP[60-i]:=GeP[60-i-1];
DaP[60-i]:=DaP[60-i-1];
QinP[60-i]:=QinP[60-i-1]; LiuQ[60-i]:=LiuP[60-i-1];
GeQ[60-i]:=GeQ[60-i-1];
DaQ[60-i]:=DaQ[60-i-1];
QinQ[60-i]:=QinQ[60-i-1]; LiuS[60-i]:=Lius[60-i-1];
GeS[60-i]:=Ges[60-i-1];
DaS[60-i]:=Das[60-i-1];
QinS[60-i]:=Qins[60-i-1]; LiuR[60-i]:=LiuR[60-i-1];
GeR[60-i]:=GeR[60-i-1];
DaR[60-i]:=DaR[60-i-1];
QinR[60-i]:=QinR[60-i-1];
end;
LiuP[0]:=PLEVEL+random(100)/25;
GeP[0]:=PLEVEL+random(100)/25;
DaP[0]:=PLEVEL+random(100)/25;
QinP[0]:=PLEVEL+random(100)/25; LiuQ[0]:=QLEVEL+random(100)/10;
GeQ[0]:=QLEVEL+random(100)/10;
DaQ[0]:=QLEVEL+random(100)/10;
QinQ[0]:=QLEVEL+random(100)/10; LiuS[0]:=Sqrt(LiuP[0]*LiuP[0]+LiuQ[0]*LiuQ[0]);
GeS[0]:=Sqrt(GeS[0]*GeS[0]+GeS[0]*GeS[0]);
DaS[0]:=Sqrt(DaS[0]*DaS[0]+DaS[0]*DaS[0]);
QinS[0]:=Sqrt(QinS[0]*QinS[0]+QinS[0]*QinS[0]); LiuR[0]:=LiuP[0]/LiuS[0];
GeR[0]:=GeP[0]/GeS[0];
DaR[0]:=DaP[0]/DaS[0];
QinR[0]:=QinP[0]/QinS[0]; Series_Liu.Clear;
Series_Ge.Clear;
Series_Da.Clear;
Series_Qin.Clear; for i:=0 to 59 do
begin
case SeriesNo of
1:
begin
Chart1.LeftAxis.Maximum:=20;
Chart1.LeftAxis.Title.Caption:='有功功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时有功功率曲线');
Series_Liu.AddXY(i,LiuP[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeP[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaP[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinP[i],IntToStr(i),clyellow);
end;
2:
begin
Chart1.LeftAxis.Maximum:=8;
Chart1.LeftAxis.Title.Caption:='无功功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时无功功率曲线');
Series_Liu.AddXY(i,LiuQ[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeQ[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaQ[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinQ[i],IntToStr(i),clyellow);
end;
3:
begin
Chart1.LeftAxis.Maximum:=25;
Chart1.LeftAxis.Title.Caption:='视在功率(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时视在功率曲线');
Series_Liu.AddXY(i,LiuS[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeS[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaS[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinS[i],IntToStr(i),clyellow);
end;
4:
begin
Chart1.LeftAxis.Maximum:=1;
Chart1.LeftAxis.Title.Caption:='功率因数(单位:万 kw)';
Chart1.Title.Text.SetText('瞬时功率因数曲线');
Series_Liu.AddXY(i,LiuR[i],IntToStr(i),clred);
Series_Ge.AddXY(i,GeR[i],IntToStr(i),clgreen);
Series_Da.AddXY(i,DaR[i],IntToStr(i),clblue);
Series_Qin.AddXY(i,QinR[i],IntToStr(i),clyellow);
end;
end;
end;
end;end.上述代码为一用数组和TCHART来显示不同情况下的数据曲线图,但为什么,显示不出来呢?
GeR[0]:=GeP[0]/GeS[0];
DaR[0]:=DaP[0]/DaS[0];
QinR[0]:=QinP[0]/QinS[0];
问题出在这一段,如果把这一段删了就性了,但这样要实现的功能就不完整了。如果加上面这一段的话,运行就会显示这样的错误:
Project dianzhanxitong.exe raised exception class EZeroDivide with message
'Floating point division by zero'.process stopped.Use Step or Run to continue.
Timer1.enabled:=true;
试试。
'Floating point division by zero'.process stopped.Use Step or Run to continue.这是 浮点数 被 0 除 的 错误,你判断一下 你的 除数,如果为零就 做你相应的其它提示,避开 做除数。
GeR[0]:=GeP[0]/GeS[0];
DaR[0]:=DaP[0]/DaS[0];
QinR[0]:=QinP[0]/QinS[0];
主要是这个错误,为什么除不了呢?
else LiuR[0] := 0.0;
以下类似
....