1. Pavel Gregor
  2. PowerBuilder
  3. Friday, 19 January 2024 11:36 AM UTC

Problem description:
When using the RegisterObject command according to the sample example from Help, it reports
RegisterObject function reports error -5 - DotNetObject is not instantiated.

However, from the sample in the attachment, it is clear that the lcs_object variable is declared and has a valid handle.

On the other hand, the create command fails to create an instance of the PowerObject type for the variable w_dotnettest. The variable w_dotnettest has no handle! So the problem is in the declaration of the PowerObject variable.

The RegisterObject function is not functional even if it is used already an existing Powerbuilder object. For example, an existing window.

So how should the variable w_dotnettest be correctly declared to make attached script work? Thanks

Pavel Gregor

Script:
Long 		ll_return
PowerObject	w_dotnettest
DotNetObject	lcs_object

// Create object DotNetObject
lcs_object = create DotNetObject
// Create object PowerObject - doesnt work
w_dotnettest = create PowerObject

// object registration
ll_return = lcs_object.RegisterObject("w_dotnettest", w_dotnettest)

if ll_return = 1 then
	MessageBox("User Object Registration", "Object w_dotnettest registered succesfully.",Information!) 
else
	MessageBox("User Object Registration", "Object registration failed w_dotnettest "+string(ll_return),Exclamation!) 
end if 

IF isvalid(lcs_object) THEN DESTROY lcs_object 
IF isvalid(w_dotnettest) THEN DESTROY w_dotnettest
Attachments (1)
Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 14:34 PM UTC
  2. PowerBuilder
  3. # 1

Hi Pavel,

While it's true that you have created an instance of DotNetObject, this object is not associated to any .NET binaries yet. My guess is that this is the "not instantiated" error you're seeing. The usual use case for DotNetObject is as an ancestor to a custom class created by the .NET Importer Tool, which automatically instantiates the .NET DLL. You can read more about this on this page: https://docs.appeon.com/pb2022r3/application_techniques/Importing_CSharp_assembly.html

 You can think of DotNetObject as a "wrapper" to a .NET Object that allows you to use it in PB. In your code, you have created the wrapper (dotnetobject) but it's not wrapping anything, which might be why you're getting that error.

Hope this helps.

Regards,
Francisco

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.