1. Manos Miliaras
  2. PowerBuilder
  3. Monday, 30 April 2018 11:55 AM UTC

Hello.

I am trying to migrate an application from powerbuilder 5 to powerbuilder 2017. I have a problem with passing an array to a powerobject and i m not sure how to resolve this. More specifically:

powerobject lpo_data[]
any la_data[]
//code to populate la_data[] with a 2 dimensional array
lpo_data[] = la_data[] //here is where the type mismatch error happens

The exact same code worked without a problem in pb5 (the lpo_data[] powerobject is getting the values of la_data[] without any problems and in the debugger it appears as a simple two dimensional array) but i get an error in pb2017
Error Number 49.
Error text = Type mismatch in array-to-object conversion at line...

I can't easily change the lpo_data[] type to "array" or "any" since i ll use lpo_data[] later on as an argument to a function that needs it to be a powerobject (li_ret = gnv_app.inv_dwcache.of_Register( ls_dddw_id, ls_dddw_name, lpo_data[] )). Is there any easy solution i m missing or the only way is to change the function that needs the powerobject lpo_data to something that works with an array (i haven't even checked if that is possible yet). Does anyone know when this change to object=array type mismatch happened and if there is any documentation of it?

Thanks in advance.

 

Alfredo Aldama Accepted Answer Pending Moderation
  1. Monday, 30 April 2018 18:17 PM UTC
  2. PowerBuilder
  3. # 1

Seria bueno ver todo el codigo para ver cual es la intención de hacer el cast de Any a Powerobject.

Un cast usualmente es algo asi:

    Clase Animal {}
    Clase Leon Hereda de Animal {}

    Leon objLeon = (Leon) Animal
     
 Pero 

 Clase Animal 
    Clase Leon Hereda de Animal

    Leon objLeon = (Leon) ArbolPanteraPiedra[]


Tal vez quieras hacer esto:
  Crear estructura 
    Estructura.VariosTipos[] = VariosTiposEnArreglo[] //donde VariosTipos es de tipo Any

y ahora si ( Prueba quiza funcione) 

powerobject MyPO
 MyPO = Estructura.VariosTipos[]

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 30 April 2018 13:30 PM UTC
  2. PowerBuilder
  3. # 2

Hi Emmanouil;

  Yes, what you are trying to do is an illegal casting. You have two arrays, one Object Pointers and the other Standard  Data types. You cannot assign one of these to the other. It does not make sense ...  lpo_data [ ] = la_data [ ]   ?????

  I suspect that this compiler loop hole was fixed in a subsequent release of PB not too far away from v5. If you tested this code with PB 11.x or 12.x I am confident that you would have needed to refactor.

 Did you run the Migration Assistant in PB 2017 against your PB 5 code?

Regards ... Chris

Comment
  1. Manos Miliaras
  2. Monday, 30 April 2018 15:11 PM UTC
Hello.



When i imported the project i got a warning that the code would migrate to the newer version since it was in an older version. Not sure if using the migration assistant would do something more. I haven't tried migrating to 11.x or 12.x but from what i ve read i m pretty confident the same problem will arise.

On my issue now, yes i get that the error makes sense although the code in the older versions runs without any errors. Is there a way to make my array into an object or something that can be handled pretty much as an object? As i said the only other alternative i see is to change all the subsequent functions (there are a few) that are supposed to take powerobjects as arguments change everything to array and pray i don't find myself in a situation where some other part of the code actually needs an object and not an array for a similar task.



Thanks.

  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 30 April 2018 15:27 PM UTC
Unfortunately (AFAIK), the only option is to refactor your code by either:





A) Passing the data as an Array of ANY    or

B) Incorporating your array of data into either a Structure or User Object that has an array of ANY inside of it. Then passing one of those as the type PowerObject. Of course, you will need to then refactor the receiver to also now parse the Any array from either the NVUO or Structure.





 

  1. Helpful
  1. Manos Miliaras
  2. Tuesday, 1 May 2018 15:15 PM UTC
Yeah that was what i was afraid i had to do. Imo both solutions are about the same; array being more straightforward and object being more versatile in case i run into different data structures ahead. I ll give it some thought and see how i ll move forward. Thanks for the input.

  1. Helpful
There are no comments made yet.
Miguel Leeuwee Accepted Answer Pending Moderation
  1. Monday, 30 April 2018 12:40 PM UTC
  2. PowerBuilder
  3. # 3

Hi,

When working with "any" data types, you first have to assign something to it, before it's final type is known and determined.

You cannot just declare an any variable and then assign it immediately to something else.

So if I understood your code (sorry if I didn't), you'd first have to assign a powerobject array to the any array.

 

HIH

MiguelL

Comment
  1. Manos Miliaras
  2. Monday, 30 April 2018 13:24 PM UTC
It is declared as a 1 dimensional array and each element has an array in it. I think its more of a semantics discussion if we should consider this a 1-dimension with array values or 2-dimension and how powerbuilder handles it and i don't think it changes anything in this specific situation. I think the main problem does not lie on the la_data[] but on the powerobject not being able to take data from an array. Even when trying to do something simpler like:



powerobject lpo_data[]

lpo_data[1]="asd"



i get a compilation error  C0008: Incompatible types in assignment: powerobject, string



I know powerobject expects an object but it seems string was considered an object or could be assigned to the powerobject back in pb5 which seems to no longer be the case.

  1. Helpful
  1. Miguel Leeuwee
  2. Monday, 30 April 2018 20:25 PM UTC
Now I see why you called it 2-dimensional :)



So yes, as others are suggesting, try using a structure object or nvo.

  1. Helpful
  1. Manos Miliaras
  2. Friday, 4 May 2018 09:07 AM UTC
Will do. Thanks.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.