Page 1 of 1

Global variable is not so global :D

Posted: Wed Jul 25, 2012 12:59 pm
by vladoportos
Hello all,

I have a little conundrum here.

I have datagrid in my program, and on its script there is this:

Code: Select all

on deleteKey
   if isEditedField is false then -- this is what I need to implement..
      doDeleteLine -- delete selected line from datagrid and DB
   else
      pass deleteKey
   end if
end deleteKey
When I press delete key while row is selected the entry is removed from DB and datagrid, but the problem is when somebody edits the cell and want to use delete key to remove letters in edited cell, it removes the whole row :-/

So I went to column behavior script and added this for editable column:

Code: Select all

on preOpenFieldEditor
   put true into isEditedField -- put true to this variable so when dell is pressed it will delete character not whole line
end preOpenFieldEditor

on exitFieldEditor
   put false into isEditedField
end exitFieldEditor
it will assign the boolean correctly but its not passed to the same variable in datagrid script, even when I define it as global ( tried to put it into card/stack script but still its not passed )

I must be missing something very basic :-/

Regards,
Vladimir

Re: Global variable is not so global :D

Posted: Wed Jul 25, 2012 1:08 pm
by shaosean

Code: Select all

global isEditedField

on deleteKey
   if isEditedField is false then -- this is what I need to implement..
      doDeleteLine -- delete selected line from datagrid and DB
   else
      pass deleteKey
   end if
end deleteKey

Code: Select all

global isEditedField

on preOpenFieldEditor
   put true into isEditedField -- put true to this variable so when dell is pressed it will delete character not whole line
end preOpenFieldEditor

on exitFieldEditor
   put false into isEditedField
end exitFieldEditor

that is not working for you? (note the extra globals added to the two scripts)

Re: Global variable is not so global :D

Posted: Wed Jul 25, 2012 1:15 pm
by jmburnod
Hi,

For script readability it is useful begin globals with "g"
global gisEditedField

Theres is a very useful scripting guide here:
http://www.fourthworld.com/embassy/arti ... html#intro

Best regards

Jean-Marc

Re: Global variable is not so global :D

Posted: Wed Jul 25, 2012 1:41 pm
by vladoportos
Thanks both its working, didn't know I have to declare it twice ( in every script )

Re: Global variable is not so global :D

Posted: Wed Jul 25, 2012 2:32 pm
by LittleGreyMan
Vladimir,

You should read chapter 5.5 Variables of the User Manuel. One subchapter details the scope of variables.

(hey, nice way of writing RTFM, isn't it? :D )

HTH

Re: Global variable is not so global :D

Posted: Wed Jul 25, 2012 2:36 pm
by vladoportos
LittleGreyMan wrote:Vladimir,

You should read chapter 5.5 Variables of the User Manuel. One subchapter details the scope of variables.

(hey, nice way of writing RTFM, isn't it? :D )

HTH
I did read it some time ago :) and remembered to use global before global variable :D but you are right !