Global variable is not so global :D

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
vladoportos
Posts: 17
Joined: Wed Jun 20, 2012 8:21 pm

Global variable is not so global :D

Post by vladoportos » Wed Jul 25, 2012 12:59 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Global variable is not so global :D

Post by shaosean » Wed Jul 25, 2012 1:08 pm

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)

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Global variable is not so global :D

Post by jmburnod » Wed Jul 25, 2012 1:15 pm

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
https://alternatic.ch

vladoportos
Posts: 17
Joined: Wed Jun 20, 2012 8:21 pm

Re: Global variable is not so global :D

Post by vladoportos » Wed Jul 25, 2012 1:41 pm

Thanks both its working, didn't know I have to declare it twice ( in every script )

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm

Re: Global variable is not so global :D

Post by LittleGreyMan » Wed Jul 25, 2012 2:32 pm

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
Best regards,

Didier

vladoportos
Posts: 17
Joined: Wed Jun 20, 2012 8:21 pm

Re: Global variable is not so global :D

Post by vladoportos » Wed Jul 25, 2012 2:36 pm

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 !

Post Reply