Please help compiling

This forum is meant for questions and discussions about the X# language and tools
Post Reply
koeidelix
Posts: 41
Joined: Tue Apr 03, 2018 10:44 am
Location: Deutschland

Please help compiling

Post 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
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Please help compiling

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

Please help compiling

Post 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
User avatar
Chris
Posts: 4905
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Please help compiling

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Please help compiling

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
koeidelix
Posts: 41
Joined: Tue Apr 03, 2018 10:44 am
Location: Deutschland

Please help compiling

Post by koeidelix »

Thank you for your answers. You confirmed a bug.
And thank you Wolfgang for your code snipped.

regards Thomas
Post Reply