Page 1 of 1
createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by Mike May >> Wed, 2 Nov 2005 16:46:27 GMT
Anyone know the syntax and parameters for Class.createInstance? I can't find anything in the 6.0.20 docs. Yet.
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by Jared >> Thu, 3 Nov 2005 0:13:49 GMT
Mike May, you are correct that there aren't any references to this in the documentation. Also, if you list the methods of the Class (Class.[Cntrl-2]) it isn't there.
What I can tell you is that its signature is:
createInstance(transient : Boolean) : InstanceType
and that if it is set to true it creates a transient instance of the class. If it is set to false it creates a persistant instance of the class.
look at this:
createTheInstance();
vars
h : Hello; //a class called hello!
it : InstanceType;
begin
beginTransaction;
Hello.instances.purge;
it := Hello.createInstance(false); //creating a persistant object create h;
h.hi := "hmm";
commitTransaction;
//creating a transient and calling its method. Hello.createInstance(true).aMethodInHello; h.sendMsg("aMethodInHello");
end;
What it seems like is that it could be a good substitute for send msg. What it is actually used for, no idea!
Of course this is hardly OO programming.
Hope this helps.
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by Mike May >> Thu, 3 Nov 2005 9:36:02 GMT
Thanks for that, it confirms what I expected (and hoped for).
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by Patwos >> Thu, 3 Nov 2005 21:57:59 GMT
Given that this method is not documented and does not show in the Ctrl+2 methods list, personally I would steer clear of using it so that you don't risk your application "breaking" in a later release of Jade should the method get removed without notice. Particularly in this case given that you can easily achieve the desired result by using the create instruction with the appropriate transient or persistent modifier as appropriate. Just my $0.02.
Hope that helps,
Pat.
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by Mike May >> Fri, 4 Nov 2005 10:28:50 GMT
I doubt it's going to break - I found it in the infrastructure code for our Jetted applications. FWIW, it's used because LINC code essentially says 'now go to screen FRED'. The createInstance method allows the creation at the framework level of a single, compact piece of code that takes the text 'FRED' and creates and initialises the form. The alternative is a big list of if-then sequences.
If you're coding directly in Jade, you don't have this issue to deal with, of course, but give a coder a tool and he'll find an excuse to use it.
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by
Patwos >> Fri, 4 Nov 2005 21:44:39 GMT
Using the create statement instead of the undocumented Class::createInstance methd does not necessarily mean a big list of if-then sequences.
Assuming you pass "FRED" in as a string, and you have a means in the high level framework of locating the Class class instance for the FRED class, you can then use the "as" modifier of the create statement to create an instance of the appropriate class instead of Class::createInstance. For example, suppose you have a local variable called classRef which references the desired Class class instance, and another local variable obj of type Object, the create statement would look similar to the following:
create obj as classRef transient;
Your code would still be generically creating the an instance of the appropriate class without a large if-then sequence and without using any undocumented or hidden methods.
Hope that helps,
Pat.
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by cnwjhp1 >> Mon, 7 Nov 2005 2:56:53 GMT
As createInstance is a Class class method, there must already be a classRef variable set up. So presumably the existing
obj:=classRef.createInstance(true);
could be directly replaced by
create obj as classRef transient;
with the only IF required being transient or not.
Wouldn't that do the same thing?
Re: createInstance
Posted: Fri Aug 07, 2009 12:55 pm
by ConvertFromOldNGs
by
Patwos >> Mon, 7 Nov 2005 3:59:10 GMT
Precisely!
I was being more verbose mainly for the benefit of the other Users reading the Newsgroup. As you say they must already be looking up the Class class instance and therefore the change required to not use createInstance should be quite trivial, with only a single if-then-else-endif being required to handle the transient modifier.