Y
yinxianglong
Unregistered / Unconfirmed
GUEST, unregistred user!
问题1
当DataSource发生变化时自己编写的数据库控件如何知道,
如TDBGrid控件,当数据库打开时自动更新表格中的内容
问题2
我自己编写的控件中的 Property ShowCursor:Boolean,为什么只能在程序运行过程中起作用,在编程过程中设置的值为什么起不作用
unit MyChart;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, TeeProcs, TeEngine, Chart, Math,Series;
type
TYinChart = class(TChart)
private
{ Private declarations }
Cursor:TShape;
FShowCursor:Boolean;
protected
{ Protected declarations }
procedure SetShowCursor(b:Boolean);
procedure MouseMove(Shift: TShiftState; X, Y: Integer);override;
public
{ virturl or override or constructor}
constructor Create(AOwner:TComponent); override ;
{ property Function And Procedure }
{ normal }
function GetXCursorPos:double;
function GetMaxX:double;
function GetMinX:double;
function GetMaxYInViewport:double;
function GetMinYinViewport:double;
procedure SetRangeX(X1,X2ouble);
procedure SetRangeY(X1,X2ouble);overload;
procedure SetRangeY;overload;
procedure ScrollX(stepouble);
procedure InvertXAxis(Value:Boolean);
procedure SetDefault;
function FindX(Series:TChartSeries;valueouble;operation:integer):Integer;//0 : <= ; 1:>=;
{ Public declarations }
published
property ShowCursor:Boolean read FShowCursor write SetShowCursor Default False;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('YinXL', [TYinChart]);
end;
{ virturl or override or constructor}
constructor TYinChart.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
//self.init
Cursor:=TShape.Create(Self);
Cursor.Visible:=false;
self.InsertControl(Cursor);
Cursor.Parent:=Self;
Cursor.Width:=2;
Cursor.Pen.Mode:=pmNotXor;
FShowCursor:=False;
end;
procedure TYinChart.SetRangeY;
begin
SetRangeY(GetMaxYInViewport,GetMinYInViewport);
end;
procedure TYinChart.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if (Shift=[ssLeft]) and (ShowCursor=True) then
Cursor.left:=X;
if (Shift=[ssLeft]) and (ShowCursor=True)and (x<BottomAxis.IStartPos) then
Cursor.left:=BottomAxis.IStartPos;
if (Shift=[ssLeft]) and (ShowCursor=True)and (x>BottomAxis.IEndPos) then
Cursor.left:=BottomAxis.IEndPos;
inherited MouseMove(Shift,x,y);
end;
{ property Function And Procedure }
procedure TYinChart.SetShowCursor(b:Boolean);
begin
FShowCursor:=b;
AllowZoom:=False;
Cursor.Visible:=b;
Cursor.Top :=LeftAxis.IStartPos;
Cursor.Height:=LeftAxis.IEndPos-LeftAxis.IStartPos;
if Cursor.Left<BottomAxis.IStartPos then
Cursor.Left:=BottomAxis.IStartPos;
if Cursor.Left>BottomAxis.IEndPos then
Cursor.Left:=BottomAxis.IEndPos;
end;
{ normal }
function TYinChart.GetXCursorPos:double;
begin
with BottomAxis do
begin
Result:=(Cursor.Left-IStartPos+1) / (IEndPos-IStartPos) * (Maximum-Minimum) + Minimum;
end;
end;
function TYinChart.FindX(Series:TChartSeries;valueouble;operation:integer):Integer;//0 : value<= ; 1:value>=;
var
i:integer;
begin
case operation of
1:
begin
for i:=series.count-1 downto 0 do
if series.XValue<=value+0.5 then
begin
result:=i;
exit;
end;
result:=0;
end;
0:
begin
for i:=0 to series.count-1 do
if series.XValue>=value-0.5 then
begin
result:=i;
exit;
end;
result:=series.count-1;
end;
else
result:=-1;
end;
end;
function TYinChart.GetMaxX:double;
var
i:integer;
begin
if self.seriesList.Count = 0 then
begin
result:=0;
exit;
end;
result:=self.Series[0].MaxXValue;
for i:=1 to SeriesList.Count-1 do
begin
if result<Series.MaxXValue then
result:=Series.MaxXValue;
end;
end;
function TYinChart.GetMinX:double;
var
i:integer;
begin
if SeriesList.count = 0 then
begin
result:=0;
exit;
end;
result:=self.Series[0].MinXValue;
for i:=1 to self.SeriesList.Count-1 do
begin
if result>Series.MinXValue then
result:=Series.MinXValue;
end;
end;
function TYinChart.GetMaxYInViewport:double;
var
i,j,k:integer;
MaxS:integer;
MinS:integer;
TMaxYouble;
b:TBarSeries;
begin
result:=-99999999.00;
for i:=0 to Self.seriesList.Count-1 do
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=mins to maxs do
begin
if result<Series.YValue[j] then
result:=Series.YValue[j];
end;
end;
for i:=0 to seriesList.Count-1 do
begin
B:=TBarSeries(Series);
if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=Mins to Maxs do
begin
TMaxy:=0;
for k:=0 to seriesList.Count-1 do if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
TMaxY:=Series[k].YValue[j]+TMaxY;
if TMaxY>=Result then result:=TMaxY
end; //end for
Exit;
end;//endif
end;//end for
end;//end function
function TYinChart.GetMinYInViewport:double;
var
i,j:integer;
MaxS:integer;
MinS:integer;
TMinYouble;
b:TBarSeries;
begin
result:=99999999.00;
for i:=0 to Self.seriesList.Count-1 do
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
B:=TBarSeries(Series);
for j:=mins to maxs do
begin
if (result>Series.YValue[j]) and not (Series is TBarSeries) and (B.MultiBar<>mbStacked) then
result:=Series.YValue[j];
end;
end;
for i:=0 to seriesList.Count-1 do
begin
B:=TBarSeries(Series);
if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=Mins to Maxs do
begin
TMinY:=Series.YValue[j];
if TMinY<=Result then result:=TMinY;
end; //end for
Exit;
end;//endif
end;//end for
end;//end function
procedure TYinChart.SetRangeX(X1,X2ouble);
begin
BottomAxis.Maximum:=Max(X1,X2);
BottomAxis.Minimum:=Min(X1,X2);
end;
procedure TYinChart.SetRangeY(X1,X2ouble);
begin
LeftAxis.Maximum:=Max(X1,X2);
LeftAxis.Minimum:=Min(X1,X2);
end;
procedure TYinChart.ScrollX(stepouble);
begin
if step>0 then
begin
BottomAxis.Maximum:=step+BottomAxis.Maximum;
BottomAxis.Minimum:=step+BottomAxis.Minimum;
end
else
begin
BottomAxis.Minimum:=step+BottomAxis.Minimum;
BottomAxis.Maximum:=step+BottomAxis.Maximum;
end
end;
procedure TYinChart.InvertXAxis(Value:Boolean);
begin
BottomAxis.Inverted:=Value;
end;
procedure TYinChart.SetDefault;
begin
LeftAxis.Automatic:=false;
BottomAxis.Automatic:=false;
View3d:=False;
end;
end.
当DataSource发生变化时自己编写的数据库控件如何知道,
如TDBGrid控件,当数据库打开时自动更新表格中的内容
问题2
我自己编写的控件中的 Property ShowCursor:Boolean,为什么只能在程序运行过程中起作用,在编程过程中设置的值为什么起不作用
unit MyChart;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, TeeProcs, TeEngine, Chart, Math,Series;
type
TYinChart = class(TChart)
private
{ Private declarations }
Cursor:TShape;
FShowCursor:Boolean;
protected
{ Protected declarations }
procedure SetShowCursor(b:Boolean);
procedure MouseMove(Shift: TShiftState; X, Y: Integer);override;
public
{ virturl or override or constructor}
constructor Create(AOwner:TComponent); override ;
{ property Function And Procedure }
{ normal }
function GetXCursorPos:double;
function GetMaxX:double;
function GetMinX:double;
function GetMaxYInViewport:double;
function GetMinYinViewport:double;
procedure SetRangeX(X1,X2ouble);
procedure SetRangeY(X1,X2ouble);overload;
procedure SetRangeY;overload;
procedure ScrollX(stepouble);
procedure InvertXAxis(Value:Boolean);
procedure SetDefault;
function FindX(Series:TChartSeries;valueouble;operation:integer):Integer;//0 : <= ; 1:>=;
{ Public declarations }
published
property ShowCursor:Boolean read FShowCursor write SetShowCursor Default False;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('YinXL', [TYinChart]);
end;
{ virturl or override or constructor}
constructor TYinChart.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
//self.init
Cursor:=TShape.Create(Self);
Cursor.Visible:=false;
self.InsertControl(Cursor);
Cursor.Parent:=Self;
Cursor.Width:=2;
Cursor.Pen.Mode:=pmNotXor;
FShowCursor:=False;
end;
procedure TYinChart.SetRangeY;
begin
SetRangeY(GetMaxYInViewport,GetMinYInViewport);
end;
procedure TYinChart.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if (Shift=[ssLeft]) and (ShowCursor=True) then
Cursor.left:=X;
if (Shift=[ssLeft]) and (ShowCursor=True)and (x<BottomAxis.IStartPos) then
Cursor.left:=BottomAxis.IStartPos;
if (Shift=[ssLeft]) and (ShowCursor=True)and (x>BottomAxis.IEndPos) then
Cursor.left:=BottomAxis.IEndPos;
inherited MouseMove(Shift,x,y);
end;
{ property Function And Procedure }
procedure TYinChart.SetShowCursor(b:Boolean);
begin
FShowCursor:=b;
AllowZoom:=False;
Cursor.Visible:=b;
Cursor.Top :=LeftAxis.IStartPos;
Cursor.Height:=LeftAxis.IEndPos-LeftAxis.IStartPos;
if Cursor.Left<BottomAxis.IStartPos then
Cursor.Left:=BottomAxis.IStartPos;
if Cursor.Left>BottomAxis.IEndPos then
Cursor.Left:=BottomAxis.IEndPos;
end;
{ normal }
function TYinChart.GetXCursorPos:double;
begin
with BottomAxis do
begin
Result:=(Cursor.Left-IStartPos+1) / (IEndPos-IStartPos) * (Maximum-Minimum) + Minimum;
end;
end;
function TYinChart.FindX(Series:TChartSeries;valueouble;operation:integer):Integer;//0 : value<= ; 1:value>=;
var
i:integer;
begin
case operation of
1:
begin
for i:=series.count-1 downto 0 do
if series.XValue<=value+0.5 then
begin
result:=i;
exit;
end;
result:=0;
end;
0:
begin
for i:=0 to series.count-1 do
if series.XValue>=value-0.5 then
begin
result:=i;
exit;
end;
result:=series.count-1;
end;
else
result:=-1;
end;
end;
function TYinChart.GetMaxX:double;
var
i:integer;
begin
if self.seriesList.Count = 0 then
begin
result:=0;
exit;
end;
result:=self.Series[0].MaxXValue;
for i:=1 to SeriesList.Count-1 do
begin
if result<Series.MaxXValue then
result:=Series.MaxXValue;
end;
end;
function TYinChart.GetMinX:double;
var
i:integer;
begin
if SeriesList.count = 0 then
begin
result:=0;
exit;
end;
result:=self.Series[0].MinXValue;
for i:=1 to self.SeriesList.Count-1 do
begin
if result>Series.MinXValue then
result:=Series.MinXValue;
end;
end;
function TYinChart.GetMaxYInViewport:double;
var
i,j,k:integer;
MaxS:integer;
MinS:integer;
TMaxYouble;
b:TBarSeries;
begin
result:=-99999999.00;
for i:=0 to Self.seriesList.Count-1 do
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=mins to maxs do
begin
if result<Series.YValue[j] then
result:=Series.YValue[j];
end;
end;
for i:=0 to seriesList.Count-1 do
begin
B:=TBarSeries(Series);
if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=Mins to Maxs do
begin
TMaxy:=0;
for k:=0 to seriesList.Count-1 do if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
TMaxY:=Series[k].YValue[j]+TMaxY;
if TMaxY>=Result then result:=TMaxY
end; //end for
Exit;
end;//endif
end;//end for
end;//end function
function TYinChart.GetMinYInViewport:double;
var
i,j:integer;
MaxS:integer;
MinS:integer;
TMinYouble;
b:TBarSeries;
begin
result:=99999999.00;
for i:=0 to Self.seriesList.Count-1 do
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
B:=TBarSeries(Series);
for j:=mins to maxs do
begin
if (result>Series.YValue[j]) and not (Series is TBarSeries) and (B.MultiBar<>mbStacked) then
result:=Series.YValue[j];
end;
end;
for i:=0 to seriesList.Count-1 do
begin
B:=TBarSeries(Series);
if (Series is TBarSeries) and (B.MultiBar=mbStacked) then
begin
minS:=Self.FindX(series,BottomAxis.Minimum,1);
maxS:=Self.FindX(series,BottomAxis.maximum,0);
for j:=Mins to Maxs do
begin
TMinY:=Series.YValue[j];
if TMinY<=Result then result:=TMinY;
end; //end for
Exit;
end;//endif
end;//end for
end;//end function
procedure TYinChart.SetRangeX(X1,X2ouble);
begin
BottomAxis.Maximum:=Max(X1,X2);
BottomAxis.Minimum:=Min(X1,X2);
end;
procedure TYinChart.SetRangeY(X1,X2ouble);
begin
LeftAxis.Maximum:=Max(X1,X2);
LeftAxis.Minimum:=Min(X1,X2);
end;
procedure TYinChart.ScrollX(stepouble);
begin
if step>0 then
begin
BottomAxis.Maximum:=step+BottomAxis.Maximum;
BottomAxis.Minimum:=step+BottomAxis.Minimum;
end
else
begin
BottomAxis.Minimum:=step+BottomAxis.Minimum;
BottomAxis.Maximum:=step+BottomAxis.Maximum;
end
end;
procedure TYinChart.InvertXAxis(Value:Boolean);
begin
BottomAxis.Inverted:=Value;
end;
procedure TYinChart.SetDefault;
begin
LeftAxis.Automatic:=false;
BottomAxis.Automatic:=false;
View3d:=False;
end;
end.