1. Paweł Kasperek
  2. PowerBuilder
  3. Thursday, 29 February 2024 16:11 PM UTC

Hi,

I have got a question about the possibility of casting an instance of Datawindows to DataStore or vice-versa. I wrote multiple functions with the same body (functionality) but different argument types Datawindow and DataStore. I didn't duplicate these functions. Is it possible to cast Datawindow to Datastore ?

Pawel

Accepted Answer
Ronnie Po Accepted Answer Pending Moderation
  1. Thursday, 29 February 2024 16:38 PM UTC
  2. PowerBuilder
  3. # Permalink

If you have time to re-architect your app, mike s did a cool presentation about creating a common ancestor for DataWindow, DataStore, DataWindowChild:

https://www.youtube.com/live/VfiC_3mntF0?si=Mmwf6mKYdXzUcfR4

Another option would be to re-code your functions using PowerObject variables in place of DataWindow and DataStore variables, and use dynamic method calls, e.g.

lpo_1.dynamic insertRow(0)

instead of

dw_1.insertRow(0) or ds_1.insertRow(0)

 

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 29 February 2024 16:43 PM UTC
  2. PowerBuilder
  3. # 1

Hi Paweł;

  Unfortunately no. :-(

  That is because the DC & the DS controls are not aligned in the System Class hierarchy.Thus no related inheritance between the two.  :-(

You can see this in the PB IDE's  object browser ...

FWIW: What I do in my STD Framework for common code implementation is to use a Global Function & pass a "PowerObject" Object Pointer. Then cast that POP in the GF to the correct object class based on using a TypeOf() command introspection.  HTH

Regards .. Chris

Comment
There are no comments made yet.
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Thursday, 29 February 2024 16:38 PM UTC
  2. PowerBuilder
  3. # 2

Hi Paweł,

I believe a straight cast is not possible, because both objects are inherently different types (even if they share a common interface). However, I think it's possible to convert from one to the other manually, please see this previous community forum post on the matter: https://community.appeon.com/index.php/qna/q-a/how-to-have-a-single-function-works-on-both-a-datawindow-and-a-datastore

 

Regards,
Francisco

Comment
  1. Paweł Kasperek
  2. Saturday, 2 March 2024 13:14 PM UTC
Thank You for links and helpful answers. After watching webinar of Mark Searer I decided to write my own decorator object for Datawindow and Datastore objects.
  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.