【发布时间】:2019-08-02 16:41:02
【问题描述】:
我的代码将 TCharts 添加到 TLayout,然后更改 TLayout 高度以适应。它工作正常。但是,在调试一些代码时,我发现了一个非常奇怪的错误。我添加了一个ShowMessage(IntToStr(7)),它在我添加第二个图表(不在第一个图表上)后导致 fmx260.bpl 中的访问冲突。在第一次违规之后,只需将鼠标移到表单上就会导致另一个访问违规。这仅发生在 Win32 中,在 iOS 和 Android 上运行良好。
我不明白为什么IntToStr(7) 会导致这种违规行为?我想知道这是否与我在声明 myCharts 向量时使用__unsafe 有关。我必须为the reason shown here. 这样做
更新:错误也发生在 ShowMessage("text") 上。也许它只是与 ShowMessage 有关?
以下是错误的屏幕截图:
这是我在 Unit1.cpp 顶部的声明:
#include "Unit1.h"
#include <FMXTee.Store.hpp>
#include <System.IOUtils.hpp>
#include <stdio.h>
#include <vector>
#include <memory>
void AddChart(); // proto function
void ReSizeCharts(); //proto function
std::vector<__unsafe TChart*> myCharts; // vector of charts
这是我的功能:
void AddChart()
{
try {
TChart *C = new TChart(Form1);
C->Parent = Form1->Layout1;
CloneChart(C, Form1->ChartTemplate, Form1, false);
C->Align = TAlignLayout::Horizontal;
C->Height = Form1->ChartTemplate->Height;
C->Width = Form1->ChartTemplate->Width;
C->MarginRight = 10;
C->Tag = myCharts.size();
C->HitTest = false;
C->Visible = true;
myCharts.push_back(C);
ReSizeCharts();
ShowMessage(IntToStr(7)); // <-------this is is where ERROR occurs
}
catch( const Exception& e )
{
ShowMessage(e.Message);
}
}
还有……
void ReSizeCharts()
{
try{
if (static_cast<int>(myCharts.size()>0)) {
myCharts[0]->Position->Y = 0;
for (int i = 1; i < static_cast<int>(myCharts.size()); i++) {
myCharts[i]->Position->Y = i*(myCharts[0]->Height);
}
Form1->Layout1->Height = static_cast<int>(myCharts.size()) * Form1->ChartTemplate->Height; // make sure Layout1 is tall enough
}
}
catch ( const Exception& e )
{
ShowMessage(e.Message);
}
}
附言错误发生在 10.3.1 和 10.3.2 上。我正在使用 C++ Builder。
【问题讨论】:
-
您是否在不涉及
TChart的单独项目中遇到相同的错误?你filed a bug report with Embarcadero了吗? -
不,在我的项目中是唯一一次看到这个错误。我试图在一个新项目中构建一个精简版本(使用上面的代码和一个 TChart 和 TButton),它工作正常。我不确定我能否做出有意义的错误报告(不过我会坚持下去)。我无法在当前项目之外复制它。
标签: firemonkey c++builder