Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PowerBuilder can't make a function call thats is within a string?

425 views
Skip to first unread message

Dean Jones

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

The only way to dynamically run code is to abstract out the common behavior
into an ancestor object. Create descendent objects to handle specific
processing and then create the object using CREATE USING command.

Example

u_nv_dynamic nv_dynamic
string sz_object

// Example sz_object = "u_nv_dynamic_copy"
sz_object = message.stringparm

nv_dynamic = CREATE USING sz_object

nv_dynamic.uf_Process()

DESTROY nv_dynamic


By doing this I can dynamically link in any code I want. All object must be
inherited from u_nv_dynamic. u_nv_dynamic must have a method uf_Process.
It actually works really well.

---
Dean Jones, CPD Professional
PowerTeam, Inc.
www.powerobjects.com
de...@powerobjects.com

Chad Bradley wrote in message ...
>I have simple code:
>
>string ls
>
>ls = "f_copyfile('C:\autoexec.bat' , 'c:\temp')"
>
>Is there a way in powerbuilder to execute that string?
>
>If not, how can I accomplish the same task without making some enormous
CASE
>statement in another function?
>
>Chad Bradley
>
>

Chad Bradley

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

Geert Van Damme

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

It's no perfect solution, but if your function
- doesn't need any arguments
- needs a string and a long
- or needs two long arguments,
and no real return value.
You can use a user event instead of a function and use triggerevent or
postevent.

Geert 'Darling' Van Damme

Chad Bradley wrote in message ...

Mahendra Dhamdhere

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

Can you explain more clearer ?
If dynamically , I want to run "Messagebox ( "test " , "test " ) "then
how will you add this code into uf_process ?


Dean Jones wrote:

> The only way to dynamically run code is to abstract out the common
> behavior
> into an ancestor object. Create descendent objects to handle specific
>
> processing and then create the object using CREATE USING command.
>
> Example
>
> u_nv_dynamic nv_dynamic
> string sz_object
>
> // Example sz_object = "u_nv_dynamic_copy"
> sz_object = message.stringparm
>
> nv_dynamic = CREATE USING sz_object
>
> nv_dynamic.uf_Process()
>
> DESTROY nv_dynamic
>
> By doing this I can dynamically link in any code I want. All object
> must be
> inherited from u_nv_dynamic. u_nv_dynamic must have a method
> uf_Process.
> It actually works really well.
>
> ---
> Dean Jones, CPD Professional
> PowerTeam, Inc.
> www.powerobjects.com
> de...@powerobjects.com
>

> Chad Bradley wrote in message ...
> >I have simple code:
> >
> >string ls
> >
> >ls = "f_copyfile('C:\autoexec.bat' , 'c:\temp')"
> >
> >Is there a way in powerbuilder to execute that string?
> >
> >If not, how can I accomplish the same task without making some
> enormous
> CASE
> >statement in another function?
> >
> >Chad Bradley
> >
> >

--
Mahendra Dhamdhere
Unicef, New York
Email:mahe...@hotmail.com

Kirk Knoernschild

unread,
Jun 12, 1998, 3:00:00 AM6/12/98
to

u_nv_dynamic is an ancestor class with uf_process declared on it, but not
implemented. You need to inherit from u_nv_dynamic and implement uf_process
at this level. This is the concrete class, call it u_nv_concrete1. Then,
the string sz_object, will have in it the string value "u_nv_concrete1".
Now, when we call create using sz_object, our object type will be of type
u_nv_concrete1, placed into the variable nv_dyanamic, and when we call
nv_dynamic.uf_process, it will exectue the uf_process on the concrete class
instantiated at run-time.

This allows us to dynamically execute functions based based on the class
instantiated at run-time. HTH.

--kirk

Mahendra Dhamdhere <nospam_m...@hotmail.com> wrote in article
<358136BE...@hotmail.com>...

Mason Liu

unread,
Jun 13, 1998, 3:00:00 AM6/13/98
to

Dynamic function calls often can be accomplished thru the Describe() and
Evaluate() functions. Of course, your function must be a global one.

Regards,

Mason Liu
Object Labs, Inc.

bga...@ibm.net

unread,
Jun 19, 1998, 3:00:00 AM6/19/98
to

Hi Chad,

There is a quick hack which you can use to do macro substitution. Make sure
your function is a global function (not in an NVO).
Then create a datastore with some bogus external source (ie. a datawindow
with 1 column of any type).
Insert one row into the datastore and follow the below example, using your
global function.

Here is an example of how the code would look:

datastore lds
string ls

ls = "f_copyfile("+"~"C:\autoexec.bat~" , ~"c:\temp~")"


lds=CREATE datastore
lds.dataobject="dw_bogus"
lds.insertrow(0)
lds.Describe( "Evaluate('"+ls+"', 1)")

DESTROY lds

Regards,

Brad Gawne
bga...@ibm.net

----------------------------------------------------
COPIED FROM ONLINE HELP
-----------------------------------------------------

Evaluating an expression Describe's Evaluate function allows you to
evaluate DataWindow painter expressions within a script using data in the
DataWindow. Evaluate has the following syntax, which you specify for
propertylist.

Evaluate ( 'expression', rownumber )

Expression is the expression you want to evaluate and rownumber is the
number of the row for which you want to evaluate the expression. The
expression usually includes DataWindow painter functions. For example, in
the following statement, Describe reports either 255 or 0 depending on the
value of the salary column in row 3:

ls_ret = dw_1.Describe( &

"Evaluate('If(salary > 100000, 255, 0)', 3)")

You can call DataWindow control functions in a script to get data from the
DataWindow, but some painter functions (such as LookUpDisplay) cannot be
called in a script. Using Evaluate is the only way to call them. (See the
example Evaluating the display value of a DropDownDataWindow below.)

-------------------------------------------------------------------------

Chad Bradley

unread,
Jul 1, 1998, 3:00:00 AM7/1/98
to

Thanks for all the replies.

Dean, I actually do have this method implemented and it does work well, but
it is getting insane having to have another object just to call a method in
another object.

This is one of the most irritating things about PowerBuilder not being 100%
Object Oriented. (Another is not being able to overload functions ONLY by
the return type...)

Chad Bradley


Dean Jones wrote in message ...


>The only way to dynamically run code is to abstract out the common behavior
>into an ancestor object. Create descendent objects to handle specific
>processing and then create the object using CREATE USING command.
>
>Example
>
>u_nv_dynamic nv_dynamic
>string sz_object
>
>// Example sz_object = "u_nv_dynamic_copy"
>sz_object = message.stringparm
>
>nv_dynamic = CREATE USING sz_object
>
>nv_dynamic.uf_Process()
>
>DESTROY nv_dynamic
>
>
>By doing this I can dynamically link in any code I want. All object must
be
>inherited from u_nv_dynamic. u_nv_dynamic must have a method uf_Process.
>It actually works really well.
>
>---
>Dean Jones, CPD Professional
>PowerTeam, Inc.
>www.powerobjects.com
>de...@powerobjects.com
>

Michael D. Kersey

unread,
Jul 1, 1998, 3:00:00 AM7/1/98
to Chad Bradley

Executing code that is dynamically created is not considered a part of most OOP
toolkits. OOP is defined by the 3 characteristics of polymorphism, encapsulation
and inheritance. None of these have anything to do with dynamically evaluation.
For example, C++ won't do it, AFAIK Delphi won't, Java shouldn't(it's too
dangerous), LISP will, Perl will.
What languages have you used that had this feature?

Dave Fish [Team PS]

unread,
Jul 2, 1998, 3:00:00 AM7/2/98
to

How would it be useful to be able to overload a function only by the
return type? How would the runtime engine "know" which function to
call? For example:

of_foo(integer ai_no) returns string
of_foo(integer ai_no) returns boolean

Which one gets called when I execute this.of_foo(100)?

Regards,
Dave Fish [Team PS]
Application Design Specialists
Sydney, Australia

On Wed, 1 Jul 1998 12:41:58 -0500, "Chad Bradley"
<cbra...@solarc.com> wrote:

>Thanks for all the replies.
>
>Dean, I actually do have this method implemented and it does work well, but
>it is getting insane having to have another object just to call a method in
>another object.
>
>This is one of the most irritating things about PowerBuilder not being 100%
>Object Oriented. (Another is not being able to overload functions ONLY by
>the return type...)
>
>Chad Bradley
>
>

Mike Niemann

unread,
Jul 2, 1998, 3:00:00 AM7/2/98
to

On Thu, 02 Jul 1998 20:51:20 GMT, df...@bigpond.com (Dave Fish [Team
PS]) wrote:

>How would it be useful to be able to overload a function only by the
>return type? How would the runtime engine "know" which function to
>call? For example:
>
>of_foo(integer ai_no) returns string
>of_foo(integer ai_no) returns boolean
>
>Which one gets called when I execute this.of_foo(100)?

As you wrote it, it doesn't matter which was called does it? [The
assumtion being that if they have the same name, they do "essentially"
the same thing.]

The compiler (at least a very smart one) could probable deal with:

string s
s = of_foo(17)

and

boolean b
b = of_foo(17)

but the more interesting case is:

string s
s = string(of_foo(17))

Regards, Mike Niemann, PBBrowser Author


Simon

unread,
Jul 3, 1998, 3:00:00 AM7/3/98
to

Presumably this is the reason PB has GetItemString, GetItemNumber, etc, but
not GetItem.

Simon

Dave Fish [Team PS] wrote in message
<359b7764...@forums.powersoft.com>...


>How would it be useful to be able to overload a function only by the
>return type? How would the runtime engine "know" which function to
>call? For example:
>
>of_foo(integer ai_no) returns string
>of_foo(integer ai_no) returns boolean
>
>Which one gets called when I execute this.of_foo(100)?
>

Dave Fish [Team PS]

unread,
Jul 3, 1998, 3:00:00 AM7/3/98
to

Mike it dawned on me later that that could be one way to implement
overloading by return type, but I think it is still pretty dangerous
because of the example you cited, and mine where I'm ignoring the
return value. I don't find not being able to do this irritating as
I've never had a need for it. To each his own I guess.

Regards,
Dave Fish [Team PS]
Application Design Specialists
Sydney, Australia

On Thu, 02 Jul 1998 23:59:21 GMT, mnie...@oowidgets.com (Mike
Niemann) wrote:

>On Thu, 02 Jul 1998 20:51:20 GMT, df...@bigpond.com (Dave Fish [Team
>PS]) wrote:
>

>>How would it be useful to be able to overload a function only by the
>>return type? How would the runtime engine "know" which function to
>>call? For example:
>>
>>of_foo(integer ai_no) returns string
>>of_foo(integer ai_no) returns boolean
>>
>>Which one gets called when I execute this.of_foo(100)?
>

0 new messages