KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Someone remind me how to .Close or .Dispose in Classic !

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Wed Nov 09, 2011 4:59 pm    Post subject: Someone remind me how to .Close or .Dispose in Classic ! Reply with quote

I cant find / remember a way of actually closing forms once open in Kixforms Classic.
I declare the variables as Global at the point of creating Forms and Controls so sub routines can see them.
I can HIDE the forms but even when the primary routine exits the form persists and if I recall this routine variables are already declared so I either have to set global flags to say it already exists or I get an Variable Already Defined Error...

Rolling Eyes
Back to top
View user's profile Send private message
enahsyemotp
KiXforms Regular
KiXforms Regular


Joined: 22 Sep 2010
Posts: 40
Location: Tulsa, OK

PostPosted: Wed Nov 09, 2011 9:07 pm    Post subject: Reply with quote

I've actually ran into similar problems when creating a System only to check the version number. I couldn't figure out how to destroy that system and recreate if the version was incorrect. I would think that there has to be a way, but I gave up and resorted to just checking the version of the actual file.
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Fri Nov 11, 2011 5:43 pm    Post subject: Reply with quote

Crying or Very sad
This is looking more like a bug than my coding !

I declare the form variables in the Function as Global. That Form can have Sub Form Functions. As Global the form data is accessible while the base form is open.
I can't .close any forms as it is not supported so I have now set global flags to say the form had been created but is hidden.
It looks like when a sub form function finishes, Kix still sees the form variables as declared yet if I re use any form function the variables are not accessible yet still seen as declared. If I don't use the Flags, I get an error saying the form variable has already been declared. Real catch 22 !
Even tried to invalidate the form by setting the variable to 0 or ReDim. Makes no difference.

SHAUN, Someone.. What am I missing.

Kixforms.dll is so usefull as its portable, no installer or major dependancies like .Net.
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Sat Nov 12, 2011 10:36 pm    Post subject: Reply with quote

enahsyemotp, Mace,

I don't have a real solution for this, just a tip to workaround enahsyemotp's problem:

To check for build number you can also do a createobject("Kixtart.Form") which has a .build property as well. Later after update routines you then can start to build the forms with "Kixtart.System"

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
enahsyemotp
KiXforms Regular
KiXforms Regular


Joined: 22 Sep 2010
Posts: 40
Location: Tulsa, OK

PostPosted: Sat Nov 12, 2011 10:49 pm    Post subject: Reply with quote

Good idea, and good to know Jochen...Thanks a ton.
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Sun Nov 13, 2011 3:26 pm    Post subject: createobject(#) constructor Reply with quote

How does one go about determining the properties and dependancies available for an object created with createobject() ?
Wondering if there is any means of Invalidating the object which MAY send an update to kixtart that the variables are no longer declared !
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Mon Nov 14, 2011 11:06 am    Post subject: Example of Problem! Reply with quote

Sad
Code:

Break On
$System = CreateObject("Kixtart.System")
$=SetOption("Explicit","on")
Global $MasterForm,$MasterLab1,$Button1,$Button2
Dim $E[3],$X

;************* MasterForm **************
$MasterForm = $System.Form()
$MasterForm.BackColor = 240,240,240
$MasterForm.Height = 200
$MasterForm.MaximizeBox = "False"
$MasterForm.MinimizeBox = "False"
$MasterForm.StartPosition = 2
$MasterForm.Text = "Master MasterForm"
$MasterForm.Width = 200

;************* MasterLab1 **************
$MasterLab1 = $MasterForm.Controls.Label("This is the master Control Form", 2, 3, 180, 23)
$MasterLab1.BackColor = 240,240,240
$MasterLab1.TextAlign = 32

;************* Button1 **************
$Button1 = $MasterForm.Controls.Button("Call Sub Form 1", 42, 57, 100, 23)
$Button1.OnClick = "$$X=SF1($$E[0],$$E[1],$$E[2],$$E[3])"

;************* Button2 **************
$Button2 = $MasterForm.Controls.Button("Call Sub Form 2", 42, 105, 100, 23)
$Button2.OnClick = "$$X=SF2($$E[0],$$E[1],$$E[2],$$E[3])"


$MasterForm.Show
While $MasterForm.Visible
 $=Execute($MasterForm.DoEvents())
 If vartype($X)>0
  $E=split($X,',')
  cls
  For Each $X in $E
   ? 'Returned Val='+val($X)
  Next
 Endif
Loop
Exit 1

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function SF1($E1,$E2,$E3,$E4)
Global $SubForm1,$Checkbox1,$Checkbox2,$Button3
Dim $E
;************* SubForm1 **************
$SubForm1 = $System.Form()
$SubForm1.BackColor = 240,240,240
$SubForm1.Height = 200
$SubForm1.MaximizeBox = "False"
$SubForm1.MinimizeBox = "False"
$SubForm1.Text = "SubSub Form 1"
$SubForm1.Width = 200

;************* CheckBox1 **************
$CheckBox1 = $SubForm1.Controls.CheckBox("Option One", 42, 23, 104, 24)
$CheckBox1.BackColor = 240,240,240
$CheckBox1.CheckAlign = 16
$CheckBox1.CheckState = $E1

;************* CheckBox2 **************
$CheckBox2 = $SubForm1.Controls.CheckBox("Option Two", 42, 57, 104, 24)
$CheckBox2.BackColor = 240,240,240
$CheckBox2.CheckAlign = 16
$CheckBox2.CheckState = $E2

;************* Button1 **************
$Button3 = $SubForm1.Controls.Button("Save Preferences", 44, 104, 100, 23)
$Button3.OnClick = "$$E=SavePref('SubForm1',$$CheckBox1.CheckState,$$CheckBox2.CheckState,$$E3,$$E4)"

$SubForm1.Show
While $SubForm1.Visible
   $=Execute($SubForm1.DoEvents())
Loop
If VARTYPE($E)>0
 $SF1=$E
Else
 $SF1=''+$E1+','+$E2+','+$E3+','+$E4
Endif
Exit $SF1
EndFunction

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function SF2($E1,$E2,$E3,$E4)
Global $SubForm2,$CheckBox3,$CheckBox4,$Button4
Dim $E
;************* SubForm2 **************
$SubForm2 = $System.Form()
$SubForm2.BackColor = 240,240,240
$SubForm2.Height = 200
$SubForm2.MaximizeBox = "False"
$SubForm2.MinimizeBox = "False"
$SubForm2.Text = "SubSub Form 2"
$SubForm2.Width = 200

;************* CheckBox3 **************
$CheckBox3 = $SubForm2.Controls.CheckBox("Option Three", 42, 23, 104, 24)
$CheckBox3.BackColor = 240,240,240
$CheckBox3.CheckAlign = 16
$CheckBox3.CheckState = $E3

;************* CheckBox4 **************
$CheckBox4 = $SubForm2.Controls.CheckBox("Option Four", 42, 57, 104, 24)
$CheckBox4.BackColor = 240,240,240
$CheckBox4.CheckAlign = 16
$CheckBox4.CheckState = $E4

;************* Button1 **************
$Button4 = $SubForm2.Controls.Button("Save Preferences", 44, 104, 100, 23)
$Button4.OnClick = "$$E=SavePref('SubForm2',$$E1,$$E2,$$CheckBox3.CheckState,$$CheckBox4.CheckState)"

$SubForm2.Show
While $SubForm2.Visible
   $=Execute($SubForm2.DoEvents())
Loop
If VARTYPE($E)>0
 $SF2=$E
Else
 $SF2=''+$E1+','+$E2+','+$E3+','+$E4
Endif
Exit $SF2
EndFunction

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function SavePref($FN,$C1,$C2,$C3,$C4)
 $SavePref=''+$C1+','+$C2+','+$C3+','+$C4
 $=execute('$$$FN.Hide')
 $masterform.refresh
 Exit $SavePref
EndFunction


If you try to access either of the SubMenus more than once you get Duplicate Definition of variable [#] because the form has not released variables on change of scope.
Back to top
View user's profile Send private message
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Mon Nov 14, 2011 11:34 am    Post subject: Much to my suprise, this WORKS Reply with quote

Substitute the GLBOAL VAR,VAR,VAR,VAR with...
Code:

Function SF1($E1,$E2,$E3,$E4)
If Not IsDeclared($SubForm1)
 Global $SubForm1
Endif
If Not IsDeclared($CheckBox1)
 Global $CheckBox1
Endif
If Not IsDeclared($CheckBox2)
 Global $CheckBox2
Endif
If Not IsDeclared($Button3)
 Global $Button3
Endif
Dim $E

and
Code:

Function SF2($E1,$E2,$E3,$E4)
If Not IsDeclared($SubForm2)
 Global $SubForm2
Endif
If Not IsDeclared($CheckBox3)
 Global $CheckBox3
Endif
If Not IsDeclared($CheckBox4)
 Global $CheckBox4
Endif
If Not IsDeclared($Button4)
 Global $Button4
Endif
Dim $E


Messy yet functional; but at least it works...
Back to top
View user's profile Send private message
gbarnas
KiXforms Regular
KiXforms Regular


Joined: 07 Mar 2003
Posts: 41
Location: Mahwah, NJ

PostPosted: Mon Nov 14, 2011 2:27 pm    Post subject: Reply with quote

Clearly, declaring globals inside a function is not desireable. You can simplify this by declaring the globals on the line prior to the function declaration. This keeps them with the related function to ease maintenance and simplifies the code to eliminate the If IsDeclared() calls. When the function loads into memory, the globals are declared just once.

Glenn
Back to top
View user's profile Send private message Visit poster's website
MACE1
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 12 Oct 2004
Posts: 130
Location: Manchester UK

PostPosted: Mon Nov 14, 2011 2:51 pm    Post subject: Understand what you are saying BUT.. Reply with quote

If I don't declare them at all and don't use EXPLICIT,ON by default they are assumed Global at point of Use; still get the error !
Yes I could declare before calling but that would be in the middle of a form and as forms have sub forms, odds are you would still get the issue as things cascade through as required.
As I structure Functions in Groups (i.e. Not inline with form) I assume if physically declaring before the Function (), the line would never be read !
I have in the past declared ALL forms as Global at the beginning of the script but that would increase the overall memory footprint substantially when the forms are generally only used to set up and configure and then seldom accessed in daily use.

Out of all of this is the fact that on changing scope it does not follow the appropriate scope variable rules, assuming I am interpreting the Documentation correctly !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic 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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group