1. Jeong Dae Ryong
  2. PowerBuilder
  3. Friday, 19 January 2024 04:54 AM UTC

I migrated from PowerBuilder 2019 to 2022.
What is the reason why the LenA function is applied or not?
If the part where the LenA function is applied is executed successfully twice, then it does not work.
If I quit PowerBuilder and run it again, it works fine.
Is there a solution?

Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 08:29 AM UTC
  2. PowerBuilder
  3. # 1

Hi.

Can you explain the following?

What is the reason why the LenA function is applied or not?
If the part where the LenA function is applied is executed successfully twice, then it does not work.

An example would be helpful...

Andreas.

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 08:21 AM UTC
  2. PowerBuilder
  3. # 2

This is an example about how to replace LenA with a different implementation. I provide this as follow-up to my answer to Miguel in https://community.appeon.com/index.php/qna/q-a/lena-function-problem-after-migrating-to-powerbuilder-2022#reply-44332.

global type lena from function_object
end type

forward prototypes
global function long lena (string as_str)
global function long lena (blob abl_blb)
end prototypes

global function long lena (string as_str);messagebox("1", "This is a custom implementation of lena")

return len(as_str)
end function

global function long lena (blob abl_blb);messagebox("2", "This is a custom implementation of lena")

return len(abl_blb)
end function

The main problem with that implementation is that from IDE you can only add one signature for a global function! The second one was added using Edit Source.

Example for calling:

messagebox("Resulting Length:", lena("testing"))

messagebox("Resulting Length:", lena(blob("testing")))

In my tests both calls will first show the messagebox inside lena and after the "Resulting Length" messagebox.

While it's possible to change that way a PB's system function with our own implementation, this should be carefully used... That's because, if someone reads the code in a later time, it may not be aware of that change... It can be confusing. Also, in that specific case we have to be sure that we won't have to work with DBCS strings.

Andreas.

Comment
  1. Miguel Leeuwe
  2. Friday, 19 January 2024 10:36 AM UTC
Thanks for that Andreas!
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 06:33 AM UTC
  2. PowerBuilder
  3. # 3

Sounds like a bug. You should open a support ticket.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 05:06 AM UTC
  2. PowerBuilder
  3. # 4

Hi,

I think you should use Len() instead of LenA().

Comment
  1. Miguel Leeuwe
  2. Friday, 19 January 2024 07:21 AM UTC
The first step would be to check if it fixes you problem. Remember there's also MidA(), etc. I'm not sure if I remember well, but I think there might be a way to replace a system function like LenA() to be calling some other function (which then would call Len()). Forgive me if I'm wrong.
  1. Helpful
  1. Andreas Mykonios
  2. Friday, 19 January 2024 08:09 AM UTC
You are right Miguel. You have to create a global function with the same signature used by LenA. Internally you will have to call len. But if in some part of your application you will have to work for some reason with dbcs string this may be a problem. Also you have to consider that LenA has two signatures: one receiving string as argument, and on expecting blobs. There is a trick to make overloaded global functions in PB, as the IDE doesn't support that. See my other reply with an example that replaces LenA...

Andreas.
  1. Helpful 1
  1. Miguel Leeuwe
  2. Friday, 19 January 2024 10:35 AM UTC
Thanks Andreas, that's great info!
  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.