我正在以编程方式创建一个bareries(Delphi2007,TeeChar 7免费版)。我想在我的图表中有相邻的条形图,所以我尝试创建多个条形图并使用多条形图属性。
在main_unit中设置multibar属性时,我得到访问冲突(调试时,如果我检查bareries对象,我可以看到multibar属性为“out of bound”)。 仅当我在创建bareries的单元中设置属性时才会收到错误。我如何在外部操纵bareries?我是否必须在unit1中为此目的设置属性?
以下是我的代码片段:
unit unit1
type TMyChart = Class
fchart: TChart;
procedure addSinglebarSeries(var X, Y: integer)
....
implementation
function TSignalchart.addSinglebarSeries(var X, Y: integer): TBarSeries;
j, n : integer;
begin
result := TBarSeries.Create(fChart);
result.AddXY(x,Y,inttostr(x), clRed);
barseries.MultiBar := mbStacked; //here no access violation
end;
----
unit main-unit
implementation
uses TeEngine, TeeProcs, unit1;
procedure myprocedure;
var
newChart : TMyChart;
X, Y := array of integer;
barseries : TBarSeries;
aX, aY, i: integer;
begin
//I create the newchart object, I create X, Y
for i := 0 to length(X) - 1 do
begin
aX := X[i];
aY := Y[i];
barseries := newChart.addsinglebarSeries(aX,aY);
end;
//barseries.MultiBar := mbStacked; //access violation!!
end;
答案 0 :(得分:1)
以下是在TeeChart
(D2007)中添加5个多栏堆叠系列的示例。 Chart1
是从组件面板中删除的TChart
组件,而Button1
是以相同方式放置的标准TButton
:
// D2007+ way to easily initialize dynamic arrays
type
TIntArray=array of Integer;
procedure TForm1.Button1Click(Sender: TObject);
var
BarSeries: TBarSeries;
X, Y: TIntArray;
i: Integer;
begin
X := TIntArray.Create(1, 2, 3, 4, 5); // SetLength and initialize rolled into one
Y := TIntArray.Create(10, 20, 30, 40, 50); // Nonsense values, of course.
Chart1.SeriesList.Clear;
for i := Low(X) to High(X) do
begin
BarSeries := TBarSeries.Create(Chart1);
BarSeries.AddXY(X[i], Y[i]);
BarSeries.MultiBar := mbStacked;
Chart1.AddSeries(BarSeries);
end;
end;
点击Button1
后的表单: