[Migrated content. Thread originally posted on 08 April 2011]
After struggling for several days and combing the documentation (it really needs better search) I find that Micro Focus Net Express 5.1 does not support Factory in COM components. You are not allowed to write factory methods and if you do they are ignored. Neither are you allowed to use Class Object (Factory) data. You ARE allowed to write ONE Factory method which must be called "new" and it cannot return or accept anything.So here's the scenario:
I have a Class that will be implemented as a COM server (IN Process .DLL). Every time it is instanced I need to update a count and build an instance stamp for that particular instance of the Class, as there can be multiple instances running in multiple threads and I need to be able to identify them. I wrote an override successfully for the "new" class and tried the following:
in the Class Methods (Factory methods):
method-id. "new".
*>---USER-CODE. Add any local storage items needed below.
working-storage section.
01 instanceStamp pic x(24).
01 isStamp pic x(20) value "AnyCo3MT".
01 isCount pic 9999 value zero.
*>---------------------------------------------------------------
procedure division.
P1.
add 1 to isCount
move isStamp to instancestamp
string
instancestamp
delimited by space
isCount
delimited by size
into instancestamp
end-string
invoke SELF "LocalinstanceStamp"
using instancestamp
end-invoke
.
end method "new".
That's what has to happen when someone instantiates the object... Because the above method runs at the Class level the count gets continually incremented as new instances are created. Obviously, there is no point in putting this count at the Object level because it will always be 1...
I need for certain Object Methods to have access to the instance stamp so that's why the Method above invokes a standard object method to set the instance stamp into object storage. Here's the object method:
... (this is OBJECT storage not CLASS storage) ...
01 local-instance-stamp pic x(24) value "Uninitialized".
*> OCWIZARD - start standard instance methods
method-id. "LocalinstanceStamp".
linkage section.
01 LIS pic x(24).
procedure division using LIS.
move LIS to local-Instance-stamp
exit method.
end method "LocalinstanceStamp".
All pretty straightforward. It compiled clean so I was optimistic, but it gives a signal error when it runs. If I comment out the invoke of "localinstanceStamp" in the Factory method ("new"), then it works fine except that I don't get the local-instance-stamp being set, of course. I thought about this and figured it might be because the Class has not yet been fully instantiated so "SELF" may not have been set. I tried setting an object reference within the "new" method and invoking "LocalinstanceStamp" on that, but nothing worked.
So HOW do you share data between Class methods and Object methods in COM servers if it doesn't support Class storage or Methods for COM? As you can see, there can be sound reasons for needing a Factory process. I have never encountered this problem before and other COBOL systems implement Factory for COM without problem.
Am I missing a directive or switch that makes storage GLOBAL or something here? (I tried G with OOCTRL but it made no difference. Neither did W. I also tried making local-instance-stamp GLOBAL, but the compiler spat the dummy on that.)
Please don't tell me I have to write a file from within the "new" method... :-)
All suggestions/ideas gratefully received,
Pion.