Register to post in forums, or Log in to your existing account
 

Post new topic  Reply to topic     Home » Forums » General zApp Discussion
Castaway
GURU


Joined: 10 Oct 2000
Posts: 793
Location: Swindon, England

PostPosted: Wed Oct 05, 2005 6:02 pm   

FindControl problems..
 
Soo..

zStore seems to be behaving itself now.. Except I got all confused when using FindControl to get the zStore object I was using, and then trying to retrieve contents from it, since Get kept returning the object itself.

In my test code, FindControl returns an object with the name mystore_N, where N is some number. Calling Get on it does not return the data I stored in the "mystore" object. Getting the object directly using $obj->mystore works fine.

So.. 1) What is FindControl finding?
and 2) Calling Get should possibly produce an error/return Nothing or whatever when it doesnt find anything, and not the object it was called on.

Code:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE zapp []>

<zapp>
 <head>
  <project files='sqlite.dll|teststore.db'/>
 </head>
 <store name='mystore' keyfield="id"/>
<!--  <sqlstore name='mystore' connection='teststore.db' filter='data'
keyfield='id'/> -->
 <window name='mainwindow' caption='Store Test' width='200' height='200'>
  <button caption='store' name='mybutton' align='top'>
<!--
   <script>
    Set S = mystore
    mystore.Put 100, "test", 200
    Dim val
    val = mystore.Get(100, "test")
    Core.MsgBox "Val is:" &amp; val
   </script>
-->
   <script language='PerlScript'>
    <![CDATA[
    my $S = $obj->mystore;
    $S->Put(100, "test", 200);
    $S->Put(100, "othertest", "thing");
    $val = $S->Get(100, "test");
    $otherval = $S->Get(100, "othertest");
    $core->MsgBox("Val is: $val");
    $core->MsgBox("Val is: $otherval");
    ]]>
   </script>
  </button>
  <button caption='retrieve' name='button2' align='bottom'>
   <script language='PerlScript'>
    <![CDATA[
#    my $S = $obj->mystore;
    my $S = $core->FindControl("mystore");
    $core->MsgBox($S->Name);
    $val = $S->Get(100, "test");
    $otherval = $S->Get(100, "othertest");
    $core->MsgBox("Val is: $val");
    $core->MsgBox("Val is: $otherval");
    ]]>
   </script>
  </button>
 </window>
</zapp>


Lady C.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23377
Location: Colorado, USA

PostPosted: Wed Oct 05, 2005 8:34 pm   
 
They should be returning the same object. If you look at the Name property of the $obj->mystore object you'll see that it also has the _N number at the end.

The way zApp works is that when you create an object, it has a "common name" that you specify, but it also has an "internal name" with the _N number appended to the end. This allows you to reuse the same "common name" but ensures that the "internal name" is unique.

This issue came up when I was designing eMobius. In a mail client, you want to open a Compose window to compose an email message. On that Compose form there is an edit box called "Subject". Now, what if the user opens two different Compose windows? Now you have two Subject objects in zApp. The internal names will be the same (Subject_1 and Subject_2 or something like that). But when you execute an Action to Send the email message, the Action can just refer to Subject.Text to get the value of the current-window's Subject field.

This is where dynamic COM objects come into play. When you access the Subject object, it is actually calling obj.Subject. The obj COM object has a property called "Subject" which returns the most current Subject object in scope (either Subject_1 or Subject_2, depending upon which Compose window currently has focus).

The core.FindControl method searches the global object stack in zApp for the most current object with the specified "common name". So, in theory, it returns the same thing as obj.Subject, just without the dynamic COM object trick.

In your example, you only have a single "mystore" object, so obj.mystore and core.FindControl("mystore") should return the same object with the same mystore_N name.

I'll try to play with your test program and see if I can figure out what is happening. Hopefully it's not some wierd PerlScript problem again. But just for kicks, check the Name property of both objects and see if they are different.
Reply with quote
Castaway
GURU


Joined: 10 Oct 2000
Posts: 793
Location: Swindon, England

PostPosted: Wed Oct 05, 2005 9:34 pm   
 
I modified it a bit.. Oddly, the result of $obj->mystore gives nothing when I call Name on it, yet calling Get works fine.. Now I'm even more confused..

Hrrm.. the VB version errors on SX.Name, which is the one that gives no name in perl, but does actually "work" with Get.. stranger and stranger..
Code:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE zapp []>

<zapp>
 <head>
  <project files='sqlite.dll|teststore.db'/>
 </head>
 <store name='mystore' keyfield="id"/>
<!--  <sqlstore name='mystore' connection='teststore.db' filter='data'
keyfield='id'/> -->
 <window name='mainwindow' caption='Store Test' width='200' height='200'>
  <button caption='store' name='mybutton' align='top'>
   <script>
    Set S = mystore
    mystore.Put 100, "test", 200
    mystore.Put 100, "othertest", "thing"
    Dim val
    Dim val2
    val = mystore.Get(100, "test")
    val2 = mystore.Get(100, "othertest")
    Core.MsgBox "Val is:" &amp; val
    Core.MsgBox "Val2 is:" &amp; val2
   </script>
<!--
   <script language='PerlScript'>
    <![CDATA[
    my $S = $obj->mystore;
    $S->Put(100, "test", 200);
    $S->Put(100, "othertest", "thing");
    $val = $S->Get(100, "test");
    $otherval = $S->Get(100, "othertest");
    $core->MsgBox("Val is: $val");
    $core->MsgBox("Val is: $otherval");
    ]]>
   </script>
-->
  </button>
  <button caption='retrieve' name='button2' align='bottom'>
   <script>
    Set SX = obj.mystore
    Set S  = Core.FindControl("mystore")
    Core.MsgBox "Name S:" &amp; S.Name
    Core.MsgBox "Name SX:" &amp; SX.Name
    Dim val
    Dim val2
    val = SX.Get(100, "test")
    val2 = S.Get(100, "othertest")
    Core.MsgBox "Val is:" &amp; val
    Core.MsgBox "Val2 is:" &amp; val2
   </script>
<!--
   <script language='PerlScript'>
    <![CDATA[
    my $SX = $obj->mystore;
    $core->MsgBox("Name SX:" . $SX->Name);
    my $S = $core->FindControl("mystore");
    $core->MsgBox("Name S:" . $S->Name);
    $val = $SX->Get(100, "test");
    $otherval = $S->Get(100, "othertest");
    $core->MsgBox("Val is: $val");
    $core->MsgBox("Val is: $otherval");
    ]]>
   </script>
-->
  </button>
 </window>

</zapp>

Lady C.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » General zApp Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
© 2009 Zugg Software. Hosted on Wolfpaw.net