Is this "clObject1" instantiated?

Posted by OctavioOlguin on 11-Mar-2017 17:36

Greetings.

I have this program, where I make the decision to instantiate an object, or not.... (i want to avoid load time if this object is not necesary).

Is there a way I can ask if this class was instantiated once (at least) so  further make other decisions... in finally block?

Thanks

Posted by Peter Judge on 13-Mar-2017 11:42

If you’ve got hangs or freezes I’d suggest looking into them first  … there may be various reason for the freeze.  Some may be your code; some may be code in the .NET library that’s doing something unexpected (or wrong). IN ABL you can use the profiler or log-manager (with 4GLTrace logging) to help you narrow down the issue .
 

Posted by Roger Blanchard on 13-Mar-2017 06:28

VALID-OBJECT ?

All Replies

Posted by jbijker on 13-Mar-2017 01:32

Why don't you make use of a static class? A static class will only be loaded once, so no need to do checks if it's loaded or not.

Otherwise you might need to use SESSION:FIRST-OBJECT and recursively make use of the NEXT-SIBLING property on this object to cycle though all objects in memory. To check if the object is of a specific type you can make use of the object's GetClass():TypeName property.

Posted by Roger Blanchard on 13-Mar-2017 06:28

VALID-OBJECT ?

Posted by Peter Judge on 13-Mar-2017 08:46

AS other have pointed out, there are a few approaches you can take. The most common pattern is something along the lines of
 
 
class MyClass:
    define public static property Instance as class MyClass no-undo
       get():
           if not valid-object(MyClass:Instance) then
              assign MyClass:Instance = new MyClass().
             
           return MyClass:Instance.
       end get.
       set.
           
    // prevents anyone other than this type instantiating
    constructor private MyClass():
    end constructor.
   
    // Add normal instance methods, properties etc    
   
end class.  
 
 
This is the singleton pattern (start at en.wikipedia.org/.../Singleton_pattern ) and you’ll find in general programmer-dom that people have strong feelings about using this pattern and how it’s implemented.  The pattern ensures that you have one and only one instance of this type at any given time.
 
 
In general I would warn against making decisions (program flow) inside a finally block. Note that there were some changes made in 11.4 to the behavior of flow-control statements in a finally block (in the doc at OpenEdge® Getting Started: New and Revised Features
11.4 Feature Comparisons : RETURN statements in a FINALLY block   documentation.progress.com/.../OpenEdge.40.html )

Posted by OctavioOlguin on 13-Mar-2017 11:24

Thanks!!! for such an elaborated (documented) answer.

My question arises from problems I get trying to use a fingerprint scanner.  I can use it, and managed to use it's internal methods to validate and get templates (fingerprint "value").  The problem came if I use repeteadly, prowin freezes.  I need to program the payroll entry screen, for 60 people in company... so not even in dreams it would be fehasible ...

I have the Initi() on the constructor, and DeInit() on destructor (Such are methods of scanner's .net module). As first attempt to make that functions available on demand (public methods) probed to be more difficult to keep memory consumption and long time running of scan module available.  I'll recode them just in case I made some error at first attempt.

Posted by Peter Judge on 13-Mar-2017 11:42

If you’ve got hangs or freezes I’d suggest looking into them first  … there may be various reason for the freeze.  Some may be your code; some may be code in the .NET library that’s doing something unexpected (or wrong). IN ABL you can use the profiler or log-manager (with 4GLTrace logging) to help you narrow down the issue .

This thread is closed