xsharp.eu • Please help compiling
Page 1 of 1

Please help compiling

Posted: Mon Mar 18, 2019 10:04 am
by koeidelix
Hi,
I'm trying to convert our application from Vulcan to X#. There are many many compiler errors, some are real errors, the most not, but I can go around them.
But this time I need help.
I get error XS1503 Argument 1: cannot convert from 'int' to 'string' accessing an element of a collection (oChartAreaCollection[0])

Please help me. Thank you.
Thomas

//--------------------------------------------------------------
Method CantCompile() As Void

Local oChart As System.Windows.Forms.DataVisualization.Charting.Chart
Local oChartAreaCollection As System.Windows.Forms.DataVisualization.Charting.ChartAreaCollection
Local oChartArea As System.Windows.Forms.DataVisualization.Charting.ChartArea

oChart := System.Windows.Forms.DataVisualization.Charting.Chart{}

// oChart:ChartAreas[0]:Area3DStyle:Rotation
oChartAreaCollection := oChart:ChartAreas
oChartArea := oChartAreaCollection[0]

Return

Please help compiling

Posted: Mon Mar 18, 2019 10:26 am
by wriedmann
Hi Thomas,

I cannot understand why the compiler is not able to understand that the Item access of the ChartAreaCollection class accepts both string and numeric indices:

https://docs.microsoft.com/en-us/dotnet ... tem_Int32_
https://docs.microsoft.com/en-us/dotnet ... em_String_

IMHO your code is correct, and I have the same error on my machine.

So you have to wait for the development team.

Wolfgang

Please help compiling

Posted: Mon Mar 18, 2019 11:26 am
by TerryB1
You appear to have commented out the assignment of oChart:ChartAreas[0] to Area3DStyle.Rotation

That line appears to have ":" and not ":=" which I expect would cause the compiler to hiccup.

Just a guess

Terry

Please help compiling

Posted: Mon Mar 18, 2019 11:32 am
by Chris
Guys, yeah this looks like a compiler bug, it's probably confused because there is both an int and a string indexer. For now, the only workaround I can think of, is to use FOREACH for this property and simply get the first item only (for index 0) etc.

Please help compiling

Posted: Mon Mar 18, 2019 11:39 am
by wriedmann
Hi Chris,

yes, I think this too....

Code: Select all

method GetChartArea( oChartAreaCollection as System.Windows.Forms.DataVisualization.Charting.ChartAreaCollection, nIndex as int ) as System.Windows.Forms.DataVisualization.Charting.ChartArea
  local oReturn as System.Windows.Forms.DataVisualization.Charting.ChartArea
  local nCurrent as int

  oReturn := null
  nCurrent := 0
  foreach oItem as System.Windows.Forms.DataVisualization.Charting.ChartArea in oChartAreaCollection
    if nCurrent == nIndex
      oReturn := oItem
    exit
  endif
  ++nCurrent
next

return oReturn
And then call with

Code: Select all

oChartArea := self:GetChartArea( oChartAreaCollection, 0 )
Wolfgang

Please help compiling

Posted: Tue Mar 19, 2019 10:09 am
by koeidelix
Thank you for your answers. You confirmed a bug.
And thank you Wolfgang for your code snipped.

regards Thomas