1. Tobias Roth
  2. PowerBuilder
  3. Tuesday, 27 December 2022 15:01 PM UTC

Hi all,

is it possible to access an enumeration of an ole object?
We want to avoid writing a constant by hand for each enum value.

for example:

Thanks
Regards Tobi

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 27 December 2022 18:38 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Tobias - 

The short answer is no, I don't think so. An enumeration is essentially a named constant, defined in the OLE object's source language, and PB really does not have the ability to access enumerated values defined in an OLE object unless they would be defined as a public property...and this just isn't done.

As a possible alternative, permit me to illustrate what I do to code non-PB enumerations in PB.

The Windows API uses LOTS of enumerations, so if I'm going to be calling WinAPI functions that require a few of these in a single event/function script, I will define the enumerated value(s) as PB constants at the start of the script, before any variable declarations, coding and using the names of the PB constants in all uppercase to make them more easily recognized as a constant. Here's an example from non-WinAPI code:

Constant Integer SHIFT   = 203  Switches between Tables A & B for a single character
Constant Integer CODE_C  = 204  Switches to encoding using Table C
Constant Integer CODE_B  = 205  Switches to encoding using Table B
Constant Integer CODE_A  = 206  Switches to encoding using Table A
Constant Integer FNC1    = 207  Application Identifier delimiter
Constant Integer START_A = 208  Begin encoding using Table A
Constant Integer START_B = 209  Begin encoding using Table B
Constant Integer START_C = 210  Begin encoding using Table C
Constant Integer STOP    = 211  Barcode ending "stop" character

When I need constants (or enumerated values) in multiple objects/scripts, I usually define these as public instance constants in an "attribute"-type of non-visual object. For example, here's a portion of the constants defined in a WinAPI attribute NVO:

// ShellExecute & ShowWindow constants(alphabetical order by name).

   // Hides the window and activates another window.
Constant Integer SW_HIDE            = 0
   // Maximizes the specified window.
Constant Integer SW_MAXIMIZE        = 3
   // Minimizes the specified window and activates the next top-level window
   // in the z-order.
Constant Integer SW_MINIMIZE        = 6
   // Activates and displays the window.  If the window is minimized or maximized,
   // Windows restores it to its original size and position.  An application
   // should specify this flag when restoring a minimized window.
Constant Integer SW_RESTORE         = 9
   // Activates the window and displays it in its current size and position.
Constant Integer SW_SHOW            = 5
   // Sets the show state based on the SW_ flag specified in the STARTUPINFO
   // structure passed to the CreateProcess function by the program that started
   // the application.  An application should call ShowWindow with this flag to
   // set the initial show state of its main window.
Constant Integer SW_SHOWDEFAULT     = 10
   // Activates the window and displays it as a maximized window.
Constant Integer SW_SHOWMAXIMIZED   = 3
   // Activates the window and displays it as a minimized window.
Constant Integer SW_SHOWMINIMIZED   = 2
   // Displays the window as a minimized window.  The active window remains active.
Constant Integer SW_SHOWMINNOACTIVE = 7
   // Displays the window in its current state.  The active window remains active.
Constant Integer SW_SHOWNA          = 8
   // Displays a window in its most recent size and position.
   // The active window remains active.
Constant Integer SW_SHOWNOACTIVATE  = 4
   // Activates and displays a window.  If the window is minimized or maximized,
   // Windows restores it to its original size and position.  An application should
   // specify this flag when displaying the window for the first time.
Constant Integer SW_SHOWNORMAL      = 1

Whenever possible, I assign names to the constants that match their original name. You may think that coding these enumerated values in PB is a pain (and I'm not arguing that point), but once done and done properly, the values are easy to find and use, and they should rarely, if ever, change. I prefer to define them in alphabetical order by name instead of by numeric value and group related constants together; this makes any particular value easier to find in a list.

HTH, John

 

Comment
  1. Tobias Roth
  2. Wednesday, 28 December 2022 08:47 AM UTC
Hi John,

Thanks for the very detailed answer, I nearly thought there were no other options.

I decided to use the constant declaration variant.

Regards Tobi

  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.