fmx260.bpl access violation ShowMessage (FMX, Win32)

  

My code adds TCharts to a TLayout and then changes the TLayout height to accommodate. It works fine. But, while debugging some code i found a really weird error. I added a ShowMessage(IntToStr(7)) and it causes an access violation in fmx260.bpl after i add the 2nd chart (not on first chart). After the first violation, simply moving mouse over the form causes another access violation. This only happens in Win32, works fine on iOS and Android.

I can’t understand why the IntToStr(7) causes this violation? I’m wondering if it could have anything to do with my use of __unsafe in declaring the myCharts vector. I had to do that for the reason shown here.

UPDATE: The errors happen with just a ShowMessage(“text”) as well. Maybe it just has to do with ShowMessage?

Here are screen shots of the errors:

Here are my declarations at top of 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

Here are my functions:

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);
}
}

And…

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);
}
}

p.s. Error occurs on 10.3.1 and 10.3.2. I’m using C++ Builder.

Comments are closed.