TChart中的TCustomSeries.Clicked事件是throw并失败

时间:2017-06-12 10:16:25

标签: c++ c++builder teechart c++builder-2006

我使用Borland C ++ Builder 2006和TChart Standard 4.04,我遇到了问题。我有一个TChart,当计算用户点击它的位置时,它无法进行此计算,似乎无法避免此问题。事实上,我的感觉是没有人点击图表,事件本身就会被抛出。

附上你可以找到错误的详细信息,我想知道究竟是做什么的,以便尽量避免错误。我已经尝试避免这个问题从图表中断开系列(更新系列内容时ParentChart属性为NULL),但它仍然会发生。

此外,您可以在相同的附加图像中找到有问题的图表(标记为红色)。下面,对该图表的一些解释。它包含3个系列:

  • 1 TPointSeries:

    • 此系列只有一个点,与下一个TPointSeries中所选的一个位置相同。

    • 它显示选定点较大,顶部图表(不会产生任何问题)显示所选项目的详细信息。

  • 1 TPointSeries

    • 这个系列代表了进化,对患者进行的每项研究都有一点。
  • 1 TLineSeries

    • 本系列代表了进化,对患者进行的每项研究都有一点。

    • 最后,它加入了上一系列的所有要点。

在这里,是图像

image

我已经能够使用下一个简单的单元重新创建问题。它包含一个显示2或3个点的图表。要在2到3点之间切换,您可以使用按钮,或单击该系列的任何一点。每次必须更新该图表时,所有系列都将被清空,并再次填充所需的数据。在这种状态下,如果您使用按钮或点击系列点,则它不会独立失败。

但是,表单还有一个复选框,简单地说,在更新图表后添加等待1秒。在这种情况下,当图表中有3个点并且您单击任何点以更改为2个点时,图表将更新并停止1秒。在这一秒之后,错误出现了。

这里是文件代码.h:

//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <vector.h>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
//---------------------------------------------------------------------------
struct TItemInChart {
    int IdMeasurement;
    int Group;
    TDateTime DateTime;
};

class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TChart *Chart;
    TLineSeries *Series_BgLine;
    TPointSeries *Series_Points;
    TPointSeries *Series_SelectedPoint;
    TButton *Button2p;
    TButton *Button3p;
    TCheckBox *cbSleepAfterUpdate;
    void __fastcall Button2pClick(TObject *Sender);
    void __fastcall ChartClickSeries(TCustomChart *Sender,
          TChartSeries *Series, int ValueIndex, TMouseButton Button,
          TShiftState Shift, int X, int Y);
    void __fastcall FormShow(TObject *Sender);
private:    // User declarations
    vector<TItemInChart*> vSetOf2Items;
    vector<TItemInChart*> vSetOf3Items;
public:     // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

这里是文件代码.cpp:

//---------------------------------------------------------------------------
#include <vcl.h>
#include <Math.hpp>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{

    //Set of 2 elements
    TItemInChart *tf = new TItemInChart();
    tf->IdMeasurement = 21;
    tf->DateTime = Now();
    tf->Group = 1;
    vSetOf2Items.push_back(tf);

    tf = new TItemInChart();
    tf->IdMeasurement = 2;
    tf->DateTime = Now() + 1;
    tf->Group = 2;
    vSetOf2Items.push_back(tf);

    //Set of 3 elements
    tf = new TItemInChart();
    tf->IdMeasurement = 31;
    tf->DateTime = Now();
    tf->Group = 1;
    vSetOf3Items.push_back(tf);

    tf = new TItemInChart();
    tf->IdMeasurement = 32;
    tf->DateTime = Now() + 1;
    tf->Group = 2;
    vSetOf3Items.push_back(tf);

    tf = new TItemInChart();
    tf->IdMeasurement = 33;
    tf->DateTime = Now() + 2;
    tf->Group = 3;
    vSetOf3Items.push_back(tf);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2pClick(TObject *Sender)
{
    //Disconecting the series and the chart
    Series_BgLine->ParentChart = NULL;
    Series_Points->ParentChart = NULL;
    Series_SelectedPoint->ParentChart = NULL;

    //Deleting alle xisnting data
    Series_Points->Clear();
    Series_SelectedPoint->Clear();
    Series_BgLine->Clear();

    //Deciding which data I'm goping to load
    vector<TItemInChart*> vSetOfItems;
    if (Sender == Button2p) {
        vSetOfItems = vSetOf2Items;
    }
    else{
        vSetOfItems = vSetOf3Items;
    }

    //Loading the data.
    TItemInChart *iic;
    for (int i = 0; i < vSetOfItems.size(); i++){
        iic = vSetOfItems[i];

        //Adding to series
        Series_Points->AddXY(i+1, iic->Group, "", clRed);
        Series_BgLine->AddXY(i+1, iic->Group, "", clWhite);

        if ( (iic->IdMeasurement == 21) || (iic->IdMeasurement == 33) ) {
            //Adding to selected point serie.
            Series_SelectedPoint->Clear();
            Series_SelectedPoint->AddXY(i + 1, iic->Group, "", clRed);
        }
    }

    //Conencting again the series with the chart
    Series_BgLine->ParentChart = Chart;
    Series_Points->ParentChart = Chart;
    Series_SelectedPoint->ParentChart = Chart;

    //Waiting only if user wants
    if (cbSleepAfterUpdate->Checked) {
        Sleep(1000);
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartClickSeries(TCustomChart *Sender,
      TChartSeries *Series, int ValueIndex, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
    //When clicking on any serie point, we change from 2 to 3 points, and vice-versa. 
    if (Series_BgLine->Count() <= 2) {
        Button2pClick(Button3p);
    }
    else{
        Button2pClick(Button2p);
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
    //When starting, we fill the chart with 3 points
    Button2pClick(Button3p);
}
//---------------------------------------------------------------------------

这里是文件代码.dfm:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 328
  ClientWidth = 556
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object Chart: TChart
    Left = -11
    Top = 0
    Width = 565
    Height = 292
    AllowPanning = pmHorizontal
    AllowZoom = False
    BackWall.Brush.Color = clWhite
    BackWall.Color = 7436151
    BackWall.Pen.Color = clGray
    BottomWall.Color = 7436151
    Foot.AdjustFrame = False
    Foot.Visible = False
    MarginBottom = 3
    MarginLeft = 10
    MarginTop = 3
    Title.AdjustFrame = False
    Title.Color = 7436151
    Title.Font.Charset = DEFAULT_CHARSET
    Title.Font.Color = clWhite
    Title.Font.Height = -11
    Title.Font.Name = 'Arial'
    Title.Font.Style = []
    Title.Text.Strings = (
      'HISTORY')
    OnClickSeries = ChartClickSeries
    BackColor = 7436151
    BottomAxis.Automatic = False
    BottomAxis.AutomaticMaximum = False
    BottomAxis.AutomaticMinimum = False
    BottomAxis.Axis.Color = clGray
    BottomAxis.Axis.Width = 1
    BottomAxis.AxisValuesFormat = '0'
    BottomAxis.ExactDateTime = False
    BottomAxis.Increment = 1.000000000000000000
    BottomAxis.LabelsAngle = 90
    BottomAxis.LabelsFont.Charset = ANSI_CHARSET
    BottomAxis.LabelsFont.Color = clWhite
    BottomAxis.LabelsFont.Height = -11
    BottomAxis.LabelsFont.Name = 'Arial'
    BottomAxis.LabelsFont.Style = []
    BottomAxis.LabelsMultiLine = True
    BottomAxis.LabelsSeparation = 1
    BottomAxis.LabelsSize = 66
    BottomAxis.LabelStyle = talValue
    BottomAxis.Maximum = 7.000000000000000000
    BottomAxis.Minimum = 1.000000000000000000
    BottomAxis.MinorTickCount = 0
    BottomAxis.MinorTickLength = 0
    BottomAxis.StartPosition = 5.000000000000000000
    BottomAxis.EndPosition = 95.000000000000000000
    Frame.Color = clGray
    LeftAxis.Automatic = False
    LeftAxis.AutomaticMaximum = False
    LeftAxis.AutomaticMinimum = False
    LeftAxis.Axis.Color = clGray
    LeftAxis.Axis.Width = 1
    LeftAxis.ExactDateTime = False
    LeftAxis.Increment = 1.000000000000000000
    LeftAxis.LabelsFont.Charset = DEFAULT_CHARSET
    LeftAxis.LabelsFont.Color = clWhite
    LeftAxis.LabelsFont.Height = -11
    LeftAxis.LabelsFont.Name = 'Arial'
    LeftAxis.LabelsFont.Style = []
    LeftAxis.LabelsMultiLine = True
    LeftAxis.Maximum = 5.000000000000000000
    LeftAxis.MinorTickCount = 0
    LeftAxis.MinorTickLength = 0
    LeftAxis.StartPosition = 10.000000000000000000
    LeftAxis.EndPosition = 90.000000000000000000
    LeftAxis.RoundFirstLabel = False
    Legend.Visible = False
    MaxPointsPerPage = 8
    ScaleLastPage = False
    View3D = False
    View3DWalls = False
    BevelOuter = bvNone
    Color = 7436151
    TabOrder = 0
    object Series_BgLine: TLineSeries
      Marks.ArrowLength = 8
      Marks.Visible = False
      SeriesColor = clWhite
      Title = 'Series_BgLine'
      Pointer.InflateMargins = True
      Pointer.Style = psRectangle
      Pointer.Visible = False
      XValues.DateTime = False
      XValues.Name = 'X'
      XValues.Multiplier = 1.000000000000000000
      XValues.Order = loAscending
      YValues.DateTime = False
      YValues.Name = 'Y'
      YValues.Multiplier = 1.000000000000000000
      YValues.Order = loNone
    end
    object Series_Points: TPointSeries
      Cursor = crHandPoint
      Marks.ArrowLength = 0
      Marks.Visible = False
      SeriesColor = 4227327
      Title = 'Series_Points'
      Pointer.HorizSize = 7
      Pointer.InflateMargins = True
      Pointer.Pen.Color = clRed
      Pointer.Pen.Visible = False
      Pointer.Style = psCircle
      Pointer.VertSize = 7
      Pointer.Visible = True
      XValues.DateTime = False
      XValues.Name = 'X'
      XValues.Multiplier = 1.000000000000000000
      XValues.Order = loAscending
      YValues.DateTime = False
      YValues.Name = 'Y'
      YValues.Multiplier = 1.000000000000000000
      YValues.Order = loNone
    end
    object Series_SelectedPoint: TPointSeries
      Marks.ArrowLength = 0
      Marks.Visible = False
      SeriesColor = clMaroon
      Title = 'Series_SelectedPoint'
      Pointer.HorizSize = 11
      Pointer.InflateMargins = True
      Pointer.Pen.Color = clRed
      Pointer.Pen.Visible = False
      Pointer.Style = psCircle
      Pointer.VertSize = 11
      Pointer.Visible = True
      XValues.DateTime = False
      XValues.Name = 'X'
      XValues.Multiplier = 1.000000000000000000
      XValues.Order = loAscending
      YValues.DateTime = False
      YValues.Name = 'Y'
      YValues.Multiplier = 1.000000000000000000
      YValues.Order = loNone
    end
  end
  object Button2p: TButton
    Left = 24
    Top = 298
    Width = 99
    Height = 25
    Caption = 'Button 2 points'
    TabOrder = 1
    OnClick = Button2pClick
  end
  object Button3p: TButton
    Left = 129
    Top = 297
    Width = 105
    Height = 25
    Caption = 'Button 3 Points'
    TabOrder = 2
    OnClick = Button2pClick
  end
  object cbSleepAfterUpdate: TCheckBox
    Left = 416
    Top = 304
    Width = 121
    Height = 17
    Caption = 'Sleep after the update'
    TabOrder = 3
  end
end

0 个答案:

没有答案