1. Roland Smith
  2. PowerBuilder
  3. Monday, 22 July 2019 17:21 PM UTC

I am able to create a window function where the datatype is set to 'structure', not a specific structure object.

When I try to call the function I get a compile error:

C0008: Incompatible types in assignment: structure, s_numbers

Is it possible to pass arbitrary structures to a function?

 

 

 

Juan Jose Marquez Martin Accepted Answer Pending Moderation
  1. Wednesday, 15 April 2020 12:01 PM UTC
  2. PowerBuilder
  3. # 1

Michael: doesn't works, or I don't achieve to make it works

 

I'm writing code for rotate an image, and I'm trying to use the PlgBlt API function, this needs to receive an array of structure X: long, Y: long

I haven't success by the moment with my tries, with many kinds of manners... I'm desperate and really needs do it, for exclude the use of any ActiveX or OCX, that's forbidden by the policies of the company

Comment
  1. Nicolas Georges
  2. Wednesday, 15 April 2020 15:18 PM UTC
It looks like you are calling a external function that points to a structure, lets say it's str_point { long x; long y }.

you should have in your calling code a local variable str_point lstr_points[3], and just pass this variable to the external function, where prototype may looks like:

boolean PlgBlt(ulong hdcDest, ref str_point lpPoint[],ulong hdcSrc, int xSrc,int ySrc, int width, int height, ulong hbmMask, int xMask, int yMask)
  1. Helpful
  1. Juan Jose Marquez Martin
  2. Wednesday, 15 April 2020 15:23 PM UTC
Thank you so much
  1. Helpful
There are no comments made yet.
Nicolas Georges Accepted Answer Pending Moderation
  1. Tuesday, 30 July 2019 16:10 PM UTC
  2. PowerBuilder
  3. # 2

Hi Roland,

You can just pass the structure object; everything else can be obtained at PBNI side (structure classname, list of fields).

You can also if you want to avoid storing the field name, store the FieldId (asking to the right PBNI api function).

But storing ids rather than names would not works well if you want to recreate a structure which definition have changed using a serialisation of a previous version (as fieldids may changed).

Nicolas.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 27 July 2019 23:38 PM UTC
  2. PowerBuilder
  3. # 3

Nicolas,

I created a PBNI non-visual extension. The function arguments are:

any astr_structure        The structure

string as_structname    Name of the structure

string as_element[]      Array of element names

 

The function serializes the structure in a custom format which includes the structure name, the name of the elements, and the data value for each element.

The string is transmitted to another program that uses PBNI to recreate the structure with each element containing the data value it had in the first program.

I wish there was a way to refer to the structure fields (elements) by number instead of by name. Then I wouldn't have to send the names.

Roland

 

Comment
  1. Kevin Ridley
  2. Monday, 29 July 2019 14:35 PM UTC
You can use the element number or name in the map object I sent you. It should work better than a structure for generic processing. Let me know if you think it's worth posting in CodeXchange.
  1. Helpful
  1. Michael Kramer
  2. Monday, 29 July 2019 14:56 PM UTC
A side line observation: This looks a lot like C#´s type = Tuple.
  1. Helpful
There are no comments made yet.
Nicolas Georges Accepted Answer Pending Moderation
  1. Saturday, 27 July 2019 00:45 AM UTC
  2. PowerBuilder
  3. # 4

Hi Roland,

for your project you may have a look at this code which is relying on a PBNI too ( CWGetField ).

It can serialize an object, structure, array, scalar into json.

 

Regards, Nicolas (xlat).

Attachments (1)
Comment
  1. Laerte Scarparo
  2. Wednesday, 16 March 2022 16:54 PM UTC
Hi Roland,

I'm not able to import and deploy a webservice project with the pbnicw.pbx.

Have you ever had problems like this? I need a function that takes a structure (unknown at design time), and gives the structures back in string format.

When i run the toJson func from another project (not webservice) it works fine...Is there any known issues with dot net component?

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 23 July 2019 14:45 PM UTC
  2. PowerBuilder
  3. # 5

Hi Roland;

   Only as an ANY variable. In my Apps though, I always re-cast the Any back to a concrete (known) structure. I have really never tried to support a "generic" structure argument.

  I you attach a simple test case to this thread or open a support ticket - then we can try and look for a workaround for you. I have personally never tried to do your approach.

Regards ... Chris

Comment
  1. Roland Smith
  2. Tuesday, 23 July 2019 15:24 PM UTC
My work around is to code a PBNI extension in C++. It will do everything I need.
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 22 July 2019 20:14 PM UTC
  2. PowerBuilder
  3. # 6

I just tried ANY and it works. Thanks!

Now I have an additional question I need to figure out. Can I use class def functions at runtime to get the element datatypes and values without assigning the any argument to the specific structure. I will be passing a second argument which is the name of the structure in a string.

 

Comment
  1. Roland Smith
  2. Tuesday, 23 July 2019 13:49 PM UTC
I can't cast it to a valid class in PB code because it is generic, I can't hard code the structure name.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 23 July 2019 14:20 PM UTC
Hi Roland;

FWIW: Can't you cast he Any to a base Structure class - then, introspect the structure item list?

Regards ... Chris
  1. Helpful
  1. Roland Smith
  2. Tuesday, 23 July 2019 14:28 PM UTC
I tried that:

Error: Cannot convert s_numbers in Any variable to structure at line 4 in function wf_numbers of object w_main.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 22 July 2019 19:06 PM UTC
  2. PowerBuilder
  3. # 7

Hi Roland;

   Have you tried using a parameter(s) declared as ANY?

Regards ... Chris

Comment
  1. Nicolas Georges
  2. Friday, 26 July 2019 23:28 PM UTC
Hi, as Powerobject should works too.
  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Monday, 22 July 2019 18:59 PM UTC
  2. PowerBuilder
  3. # 8

Hi Roland,

I would expect datatype = ANY would allow you to pass any struct. I haven't tried to pass a struct as ANY to a WinAPI function. There may other issues  involved.

HTH /Michael

Comment
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.