BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange Error when plotting data with TChart

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue May 01, 2007 11:57 pm    Post subject: Strange Error when plotting data with TChart Reply with quote



I have a TChart and one button in a project. The button just plots
points to the chart. If I call the AddXY() function it bombs if the
data is from an array created outside this routine or it bombs if the
"Y" data is a constant like dVal = 18100. NOTE: If the dVal = 1817 it
won't bomb, if dVal = 1818 it will bomb.
( dVal = 0x71A; //0x71A (1818)fails //0x719 (1817) passes )

Any ideas why this occurs? The only difference I can see is that one
is calculated on the fly and the other is known by the compiler at
compile time(this doesn't explain why dVal < 1817 passes but dVal >=
1818 fails though)
Thanks...

void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i;
int iVal;
double dVal;

//dVal = 18180; // Bombs, when used
for(i=0;i<10000;i++)
{
//dVal = 8000; // Bombs, when used
//dVal = i*sin(i*3.14/360); // Works, when used
tcDataPlot->Series[0]->AddXY(i,dVal,"",clBlue); //i,10000,"",
clBlack);
}

}

//---------------------------------------------------------------------------

"Access violation at address 40901083 in module 'tee60.bpl'. Write of
address 01754000"

"Project test.exe raised exception class EInvalidPointer with message
'Invalid pointer operation'. Process stopped"
Back to top
Oliver Rutsch
Guest





PostPosted: Wed May 02, 2007 8:10 am    Post subject: Re: Strange Error when plotting data with TChart Reply with quote



Hi,

Quote:
I have a TChart and one button in a project. The button just plots
points to the chart. If I call the AddXY() function it bombs if the
data is from an array created outside this routine or it bombs if the
"Y" data is a constant like dVal = 18100. NOTE: If the dVal = 1817 it
won't bomb, if dVal = 1818 it will bomb.
( dVal = 0x71A; //0x71A (1818)fails //0x719 (1817) passes )


I think you're using BCB6, right? In BCB5 there was a serious problem in
the TChart component when you're using Y-axis autoscaling. The problem
was that the autoscaling algorithm failed with an AV when ALL Y-values
in the diagram had the same value. What you can try is:

1. Disable autoscaling for the Y-axis.

2. Make sure that you have at least two different y-values in the
diagram. The AV occurs when the diagram repaints, so make sure that you
add your values without interruption.

3. Try this workaround:

Add in the constructor of your form:

MySeries->OnAfterAdd=AfterAdd;

Add this event in your form:

void __fastcall TMyForm::AfterAdd(TChartSeries * Sender, int ValueIndex)
{
TCustomAxisPanel * Parent=Sender->ParentChart;
if (!Parent)
return;
// not if zoomed!
if (Parent->Zoomed)
return;
// Workaround to prevent access violation in TChart when
// Min/Max values are the same.
const double tmpVal = Sender->YValues->MaxValue;
// remember initial value of the Automatic property
const static bool y_auto=Sender->GetVertAxis->Automatic;

if (tmpVal!=Sender->YValues->MinValue)
{
// already different min/max values
Sender->GetVertAxis->Automatic = y_auto;
return;
}
bool SameVal=true;
for (int i=0;i<Parent->SeriesList->Count;i++)
{
const double SeriesMin=Parent->Series[i]->YValues->MinValue;
const double SeriesMax=Parent->Series[i]->YValues->MaxValue;
if (Parent->Series[i]->Count() && (tmpVal!=SeriesMin ||
tmpVal!=SeriesMax))
{
SameVal=false;
break;
}
}
if (SameVal)
{
// Set Automatic to false to prevent AV in TChart
Sender->GetVertAxis->Automatic = false;
Sender->GetVertAxis->SetMinMax(tmpVal-1, tmpVal+1);
}
else
Sender->GetVertAxis->Automatic = y_auto; // set to initial value
}


Bye,


--
Dipl. Ing. Oliver Rutsch
EMail: orutsch (AT) sympatec (DOT) com
Sympatec GmbH
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.