Re: Remedial question about components

2017-04-18 Thread David Adams via 4D_Tech
On Tue, Apr 18, 2017 at 4:59 PM, Keisuke Miyako via 4D_Tech <
4d_tech@lists.4d.com> wrote:

+ when the host and component share the same methods names
>
> this is also documented (see Naming conflicts: masking methods)
> the host takes precedence over component
> http://doc.4d.com/4Dv16/4D/16/Component-installation-and-
> compatibility.300-3048906.en.html


I wouldn't have wanted to count on this mechanism alone, but I did want to
see it in action. With 16.0 on macOS I can't generate such a warning.
Perhaps 4D Compiler has changed?
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Wayne Stewart via 4D_Tech
Forgot to say.

Client Server 1000 tests in under a second with 1600 methods in host or 800
methods in component.


Regards,

Wayne


[image: --]
Wayne Stewart
[image: http://]about.me/waynestewart



On 19 April 2017 at 12:07, Wayne Stewart  wrote:

> David,
>
> Using a bit of discipline you can easily set this up
>
> Create a method in each component like this, just change the suffix on the
> method name.
>
>// 
>
>   // Project Method: MethodExists_Comp (Method Name) --> Boolean
>
>
>   // Checks if a method exists in the component
>
>
>   // Access: Shared
>
>
>   // Parameters:
>
>   //   $1 : Text : The method name to check for in component
>
>
>   // Returns:
>
>   //   $0 : Boolean : True if the method exists in the component
>
>
>   // Created by Wayne Stewart (2017-04-18T14:00:00Z)
>
>   // wa...@4dsupport.guru
>
>   // 
>
>
>
> *C_BOOLEAN*(*$0*)
>
> *C_TEXT*(*$1*)
>
>
> *C_BOOLEAN*($exists_b)
>
> *C_TEXT*($methodName_t)
>
>
> *ARRAY TEXT*($MethodNames_at;0)
>
>
> $methodName_t:=*$1*
>
>
> *METHOD GET NAMES*($MethodNames_at;$methodName_t)  // No * => Component
> method
>
>
> $exists_b:=(*Size of array*($MethodNames_at)>0)
>
>
> *$0*:=$exists_b
>
>
> Then you can create a method in the host database like this:
>
>   // 
>
>   // Project Method: MethodExists (Method Name {; Context}) --> Boolean
>
>
>   // Checks if a method exists in the host
>
>   // Optionally you can pass a context
>
>   //   Either the component Prefix (eg Find or LBOX etc)
>
>   // or "Host"
>
>
>   // Access: Shared
>
>
>   // Parameters:
>
>   //   $1 : Text : Method Name
>
>   //   $2 : Text : Context (optional)
>
>
>   // Returns:
>
>   //   $0 : Boolean : True if the method exists
>
>
>   // Created by Wayne Stewart (2017-04-18T14:00:00Z)
>
>   // wa...@4dsupport.guru
>
>   // 
>
>
> *C_BOOLEAN*(*$0*)
>
> *C_TEXT*(*$1*;*$2*)
>
>
> *C_BOOLEAN*($exists_b)
>
> *C_TEXT*($methodName_t;$Context_t;$CmptMethodExists_t)
>
>
> *ARRAY TEXT*($MethodNames_at;0)
>
>
> $methodName_t:=*$1*
>
> $Context_t:="Host"
>
>
> *If *(*Count parameters*=2)
>
> $Context_t:=*$2*
>
> *End if *
>
>
> *If *($Context_t="Host")
>
> *METHOD GET NAMES*($MethodNames_at;$methodName_t;*)  // * => Check host
> methods (which it would do anyway)
>
> $exists_b:=(*Size of array*($MethodNames_at)>0)
>
>
> *Else *
>
> $CmptMethodExists_t:="MethodExists_"+$Context_t
>
> *EXECUTE METHOD*($CmptMethodExists_t;$exists_b;$methodName_t)
>
>
> *end if*
>
>
> *$0*:=$exists_b
>
>
>
>
>
>
> Regards,
>
> Wayne
>
>
> [image: --]
> Wayne Stewart
> [image: http://]about.me/waynestewart
> 
>
>
> On 19 April 2017 at 09:36, David Adams  wrote:
>
>> Hey Wayne,
>>
>> Thanks for the idea. I like the way you flip things around from how I
>> think, it's great. In this case, your suggestion doesn't apply, but I'm
>> adding your suggestion to your other idea about manufactured methods to my
>> "things to think about" list.
>>
>> Anyway, I haven't explained my constraints clearly enough to give you a
>> chance to help. Rather than waste more of your time, I'll explain more
>> about my circumstances. I'm using CALL FORM and CALL WORKER. These accept a
>> window reference or worker reference, a method name, and (optionally)
>> method parameters.
>>
>>The recipient identifier (window or worker) ways *where* to run the
>> code.
>>The method name says *what* code to run.
>>The parameters work just like with new process, etc, they get fed into
>> the instance of the method that runs.
>>
>> The method name has to be a method name - but 4D treats it as a string.
>> There is no validation done when you make the call.
>>
>> CALL PROCESS("MyWonderfulWorker";"D'oh! No Such Method Exists")
>>
>> There's no error set here, no OK variable, etc. It's on the *recipient*
>> side that you run into trouble. 4D takes the string and adds it to the end
>> of the code stack (whatever you call that) in the target's context. So, if
>> it's a worker, your method call is added to the end of that process and run
>> once any existing code finishes. Same with a worker, your code is appended
>> there. What happens after that is just like what would happen if you ran an
>> EXECUTE in that context by hand. Namely, you get an error if you run a bad
>> method name.
>>
>> So, the error is caused by the sender but occurs in the recipient. There
>> is *no* On Call Received-like event/function/method/hook on the recipient
>> side to inspect the code before it's run. That's all under the hood. 4D
>> checks it and tosses an error, if the method name is bad. If I want to
>> prevent bad calls from being sent, I need to error check the method name on
>> the *sender* side. My component is acting as 

Re: Remedial question about components

2017-04-18 Thread Wayne Stewart via 4D_Tech
David,

Using a bit of discipline you can easily set this up

Create a method in each component like this, just change the suffix on the
method name.

   // 

  // Project Method: MethodExists_Comp (Method Name) --> Boolean


  // Checks if a method exists in the component


  // Access: Shared


  // Parameters:

  //   $1 : Text : The method name to check for in component


  // Returns:

  //   $0 : Boolean : True if the method exists in the component


  // Created by Wayne Stewart (2017-04-18T14:00:00Z)

  // wa...@4dsupport.guru

  // 



*C_BOOLEAN*(*$0*)

*C_TEXT*(*$1*)


*C_BOOLEAN*($exists_b)

*C_TEXT*($methodName_t)


*ARRAY TEXT*($MethodNames_at;0)


$methodName_t:=*$1*


*METHOD GET NAMES*($MethodNames_at;$methodName_t)  // No * => Component
method


$exists_b:=(*Size of array*($MethodNames_at)>0)


*$0*:=$exists_b


Then you can create a method in the host database like this:

  // 

  // Project Method: MethodExists (Method Name {; Context}) --> Boolean


  // Checks if a method exists in the host

  // Optionally you can pass a context

  //   Either the component Prefix (eg Find or LBOX etc)

  // or "Host"


  // Access: Shared


  // Parameters:

  //   $1 : Text : Method Name

  //   $2 : Text : Context (optional)


  // Returns:

  //   $0 : Boolean : True if the method exists


  // Created by Wayne Stewart (2017-04-18T14:00:00Z)

  // wa...@4dsupport.guru

  // 


*C_BOOLEAN*(*$0*)

*C_TEXT*(*$1*;*$2*)


*C_BOOLEAN*($exists_b)

*C_TEXT*($methodName_t;$Context_t;$CmptMethodExists_t)


*ARRAY TEXT*($MethodNames_at;0)


$methodName_t:=*$1*

$Context_t:="Host"


*If *(*Count parameters*=2)

$Context_t:=*$2*

*End if *


*If *($Context_t="Host")

*METHOD GET NAMES*($MethodNames_at;$methodName_t;*)  // * => Check host
methods (which it would do anyway)

$exists_b:=(*Size of array*($MethodNames_at)>0)


*Else *

$CmptMethodExists_t:="MethodExists_"+$Context_t

*EXECUTE METHOD*($CmptMethodExists_t;$exists_b;$methodName_t)


*end if*


*$0*:=$exists_b






Regards,

Wayne


[image: --]
Wayne Stewart
[image: http://]about.me/waynestewart



On 19 April 2017 at 09:36, David Adams  wrote:

> Hey Wayne,
>
> Thanks for the idea. I like the way you flip things around from how I
> think, it's great. In this case, your suggestion doesn't apply, but I'm
> adding your suggestion to your other idea about manufactured methods to my
> "things to think about" list.
>
> Anyway, I haven't explained my constraints clearly enough to give you a
> chance to help. Rather than waste more of your time, I'll explain more
> about my circumstances. I'm using CALL FORM and CALL WORKER. These accept a
> window reference or worker reference, a method name, and (optionally)
> method parameters.
>
>The recipient identifier (window or worker) ways *where* to run the
> code.
>The method name says *what* code to run.
>The parameters work just like with new process, etc, they get fed into
> the instance of the method that runs.
>
> The method name has to be a method name - but 4D treats it as a string.
> There is no validation done when you make the call.
>
> CALL PROCESS("MyWonderfulWorker";"D'oh! No Such Method Exists")
>
> There's no error set here, no OK variable, etc. It's on the *recipient*
> side that you run into trouble. 4D takes the string and adds it to the end
> of the code stack (whatever you call that) in the target's context. So, if
> it's a worker, your method call is added to the end of that process and run
> once any existing code finishes. Same with a worker, your code is appended
> there. What happens after that is just like what would happen if you ran an
> EXECUTE in that context by hand. Namely, you get an error if you run a bad
> method name.
>
> So, the error is caused by the sender but occurs in the recipient. There
> is *no* On Call Received-like event/function/method/hook on the recipient
> side to inspect the code before it's run. That's all under the hood. 4D
> checks it and tosses an error, if the method name is bad. If I want to
> prevent bad calls from being sent, I need to error check the method name on
> the *sender* side. My component is acting as a message hub for a
> publish-subscribe system (I'll show it to you when I see you in May), which
> makes is an entirely sensible place to do the validation.
>
> Okay, that's more background. So what I need to check for when it comes to
> method names:
>
> * The method exists.
> * The method exists in the right context (component or host)
> * The method name is unique in the component and host.
>
> Possible outcomes if you don't check these things are:
>
> a) There's no problem and 4D runs the code. (The method name exists and is
> unique.)
> b) 4D throws an error 

Re: Remedial question about components

2017-04-18 Thread David Adams via 4D_Tech
Hey Wayne,

Thanks for the idea. I like the way you flip things around from how I
think, it's great. In this case, your suggestion doesn't apply, but I'm
adding your suggestion to your other idea about manufactured methods to my
"things to think about" list.

Anyway, I haven't explained my constraints clearly enough to give you a
chance to help. Rather than waste more of your time, I'll explain more
about my circumstances. I'm using CALL FORM and CALL WORKER. These accept a
window reference or worker reference, a method name, and (optionally)
method parameters.

   The recipient identifier (window or worker) ways *where* to run the code.
   The method name says *what* code to run.
   The parameters work just like with new process, etc, they get fed into
the instance of the method that runs.

The method name has to be a method name - but 4D treats it as a string.
There is no validation done when you make the call.

CALL PROCESS("MyWonderfulWorker";"D'oh! No Such Method Exists")

There's no error set here, no OK variable, etc. It's on the *recipient*
side that you run into trouble. 4D takes the string and adds it to the end
of the code stack (whatever you call that) in the target's context. So, if
it's a worker, your method call is added to the end of that process and run
once any existing code finishes. Same with a worker, your code is appended
there. What happens after that is just like what would happen if you ran an
EXECUTE in that context by hand. Namely, you get an error if you run a bad
method name.

So, the error is caused by the sender but occurs in the recipient. There is
*no* On Call Received-like event/function/method/hook on the recipient side
to inspect the code before it's run. That's all under the hood. 4D checks
it and tosses an error, if the method name is bad. If I want to prevent bad
calls from being sent, I need to error check the method name on the
*sender* side. My component is acting as a message hub for a
publish-subscribe system (I'll show it to you when I see you in May), which
makes is an entirely sensible place to do the validation.

Okay, that's more background. So what I need to check for when it comes to
method names:

* The method exists.
* The method exists in the right context (component or host)
* The method name is unique in the component and host.

Possible outcomes if you don't check these things are:

a) There's no problem and 4D runs the code. (The method name exists and is
unique.)
b) 4D throws an error because the method name doesn't exist.
c) 4D runs the wrong copy (in the component) because of a redundant name.

My goal is to find an efficient way to know if a method name call
originating from a component is safe.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Wayne Stewart via 4D_Tech
David,

What I occasionally do is use Execute Method and have two "identical"
project methods (other than the name).

$Method_t:="My_Method"
If (RunningInComponent)
  $Method_t:=$Method_t+"Comp"
else
  $Method_t:=$Method_t+"Host"
end if

That way I can test when running the component only, I can call the host
version from within the component easily but still have access to the
component version, and finally I can call either version from the host as
well.

Is that helpful?





Regards,

Wayne


[image: --]
Wayne Stewart
[image: http://]about.me/waynestewart



On 18 April 2017 at 22:23, David Adams via 4D_Tech <4d_tech@lists.4d.com>
wrote:

> On Tue, Apr 18, 2017 at 10:16 PM, Wayne Stewart via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
>
> > David,
> >
> > Why don't you get the component to just create the method in the host
> > before calling it? (Assuming it doesn't exist yet).
>
>
> Huh, I would never have thought of that. That won't help out in this
> particular case, but I'll try thinking about the idea in general in the
> next couple of days just to look at things from a different angle.
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
>
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread David Adams via 4D_Tech
On Tue, Apr 18, 2017 at 10:16 PM, Wayne Stewart via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> David,
>
> Why don't you get the component to just create the method in the host
> before calling it? (Assuming it doesn't exist yet).


Huh, I would never have thought of that. That won't help out in this
particular case, but I'll try thinking about the idea in general in the
next couple of days just to look at things from a different angle.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Wayne Stewart via 4D_Tech
David,

Why don't you get the component to just create the method in the host before 
calling it? (Assuming it doesn't exist yet).

This only works interpreted but we do that all the time in the Foundation 
world. 

Regards,

Wayne
Sent from my iPhone

> On 18 Apr 2017, at 21:56, David Adams via 4D_Tech <4d_tech@lists.4d.com> 
> wrote:
> 
> On Tue, Apr 18, 2017 at 9:48 PM, Keisuke Miyako via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
> 
>> to recap,
>> 
>> why do you need to know from a compiled component if the host is
>> interpreted?
>> 
> 
> I'd like to validate that the host method name I'm being passed is valid in
> two ways:
> 
> 1) The name actually exists in the host.
> 2) The name does not match a name in the component.
> 
> If the host is compiled, I can grab all method names once and cache them in
> the worker. (My component manages a worker.) Then I can search on that list
> without reloading it. If the host is interpreted, I can't be sure that the
> list of method names has not changed since I last checked on the name.
> 
> I may be over-thinking this - my concern is that METHOD GET NAMES will be a
> bit slow. I haven't retested this to confirm, I just remember using it in
> V13 and finding it a bit slow on a structure with 4,000+ methods.
> 
> Thanks.
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread David Adams via 4D_Tech
On Tue, Apr 18, 2017 at 9:48 PM, Keisuke Miyako via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> to recap,
>
> why do you need to know from a compiled component if the host is
> interpreted?
>

I'd like to validate that the host method name I'm being passed is valid in
two ways:

1) The name actually exists in the host.
2) The name does not match a name in the component.

If the host is compiled, I can grab all method names once and cache them in
the worker. (My component manages a worker.) Then I can search on that list
without reloading it. If the host is interpreted, I can't be sure that the
list of method names has not changed since I last checked on the name.

I may be over-thinking this - my concern is that METHOD GET NAMES will be a
bit slow. I haven't retested this to confirm, I just remember using it in
V13 and finding it a bit slow on a structure with 4,000+ methods.

Thanks.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Keisuke Miyako via 4D_Tech
to recap,

why do you need to know from a compiled component if the host is interpreted?

> 2017/04/18 19:16、David Adams via 4D_Tech <4d_tech@lists.4d.com> のメール:
>
> is there a way to find out if the host is compiled without having the
> host pass that information into the component?




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Keisuke Miyako via 4D_Tech
I think you can do something like

$name:="test"

(""#METHOD Get path(Path project method;$name))

is a "local" method

(""#METHOD Get path(Path project method;$name;*)) //with asterisk

is a "host" method

> 2017/04/18 19:16、David Adams via 4D_Tech <4d_tech@lists.4d.com> のメール:
> As far as I know, the only way that I can detect and screen for method name
> conflicts at runtime is by calling METHOD GET NAMES.




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Remedial question about components

2017-04-18 Thread Keisuke Miyako via 4D_Tech
Hello,

+ to check current execution context

Structure file=Structure file(*)

this is documented (see example 2)
http://doc.4d.com/4Dv15/4D/15.4/Structure-file.301-3274414.en.html

+ when the host and component share the same methods names

this is also documented (see Naming conflicts: masking methods)
the host takes precedence over component
http://doc.4d.com/4Dv16/4D/16/Component-installation-and-compatibility.300-3048906.en.html

name conflicts of this sort are reported by the compiler, if the call is 
tokenised.

> 2017/04/18 14:51、David Adams via 4D_Tech <4d_tech@lists.4d.com> のメール:
>
> So, there are two different methods with the same name - one in the
> component and one in the host. As far as I can tell, this won't work. 4D
> calls the copy in the component and nothing happens in the host. I just ran
> into this by accident, check the docs...and couldn't find any sort of
> discussion. It looks like there's no explicit syntax to say 'execute in the
> host method.'
>
> Is this correct? If so, how do people deal with this problem? All that I
> can think of is to validate the input within the component. Before calling
> the callback, you check if it's in the method lest for the component and
> the host. Seems inefficient. Also, I'm not sure if this is even
> possible...is there a way to test the calling context? Meaning, is there a
> way to know if the call originates from the host or from another component
> method? The component relies on callbacks internally as well.




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Remedial question about components

2017-04-17 Thread David Adams via 4D_Tech
I check out 4D's components every few versions and am now doing so in V16.

I've got a big pile of code that would be nicer to use as a component. It's
got a few well-defined entry points/functions accessed via passed
parameters and callbacks, so there are already no shared variables to worry
about.

But the callbacksThe main code runs in a worker that takes calls via
CALL WORKER. Sometimes, the outside code needs an answer, which is
delivered via a callback via CALL WORKER or CALL FORM. So, an input to the
component is the name of method in the host database.

The basic mechanics of this are fine: set the callback method in the host
as 'shared with component and host database'. But now we get to my question:

What if there is already a method inside of the component with the same
 name in the host?

Say I've got

 InfoCatchCallback  - not shared with host (nor should it be)

...in the component (I don't, just saying) and then in the host database
I've got

   InfoCatchCallback  - shared with component (must be)

So, there are two different methods with the same name - one in the
component and one in the host. As far as I can tell, this won't work. 4D
calls the copy in the component and nothing happens in the host. I just ran
into this by accident, check the docs...and couldn't find any sort of
discussion. It looks like there's no explicit syntax to say 'execute in the
host method.'

Is this correct? If so, how do people deal with this problem? All that I
can think of is to validate the input within the component. Before calling
the callback, you check if it's in the method lest for the component and
the host. Seems inefficient. Also, I'm not sure if this is even
possible...is there a way to test the calling context? Meaning, is there a
way to know if the call originates from the host or from another component
method? The component relies on callbacks internally as well.

Anyway, I'm looking for some confirmation, clarification, and a solution
that doesn't depend on luck.

Sorry if this is super basic and obviousbut I did warn that it's a
remedial question...
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**