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

Registry Editor (Readonly) using new Event Strategy

 
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET Discussion
View previous topic :: View next topic  
Author Message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Jan 13, 2006 10:33 pm    Post subject: Registry Editor (Readonly) using new Event Strategy Reply with quote

Im working on a REGEDIT look-alike using Kixforms.NET ... the purpose is to test-out the new event strategy that was introduced in the latest development build ... basically here is a quick run-down of that...

In .net, an event gets called directly by the .net library - and there are "event arguments" that are automatically passed to the event function. In .net, an event looks something like this:

Code:

Public Sub KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)

 ' Your event code here ...

End Sub


The event function gets passed an Object that is the "sender" of the event, and it gets passed an object that derives from EventArgs - that contains any "data" that goes with the event (for example, a KeyDown event passes a KeyEventArgs object that contains the KeyCode of the key that went down). Up until now, events in Kixforms.Net were handled like this:

Code:

Function KeyDown()

 $sender = <the object you assumed sent the event>

 $e = $sender.KeyDownEventArgs

 ; Your event code here...

EndFunction


Basically the sender you have to figure out yourself (its usually not too hard if you only got one object triggering the event). And the arguments to the event I encoded in special (non standard) properties named after the event itself (ie, KeyDown has KeyDownEventArgs. KeyUp has KeyUpEventArgs) and the EventArgs resided inside the sender.

Well ... here is the new (more .netty way) of handling events in Kixforms.NET

Code:

Function KeyDown()

 $sender = $System.Sender

 $e = $System.Event

 ; Your event code here, for example ...

 ?"KeyCode = " $e.KeyCode

EndFunction


So the sender of the event is available from the System.Sender property, and the specific EventArgs that goes with the event is found in System.Event ... having said that, one can (and I've done) setup something that works almost identically to the way .net works. Here's how:

Setup your call to the event like this:

Code:

$Form.KeyDown = "FormKeyDown($$System.Sender, $$System.Event)"


The event function gets setup like this:

Code:

Function FormKeyDown($sender, $e)

 ; Your event code here for example ...

 ?"KeyCode = " $e.KeyCode

EndFunction


The other kinda cool thing is that .net has whats called "Event Signatures" - basically its the way an event function gets called and what parameters get passed (how it looks). In .net, the signature for event function calls are always the same (eg, they get passed two parameters - the sender and an eventargs). Using this strategy, the same can be said for Kixforms ... all your event functions can take-on the following "signature":

Code:

Function FunctionName($sender, $e)

 ; Your event code here ...

EndFunction


And no matter what event your using - the signature for it is always the same. The only thing that will differ is the actual "EventArgs" that gets passed in $e.

Please find attached the REGEDIT look-alike script. Its a work-in-progress - nothing ground-breadking here - been done more than a few times in the past ...

If you want to see a "working with EventArgs" example, check-out the TreeView_BeforeExpand event function. In there, a check is done to see if one is trying to expand the HKEY_CLASSES_ROOT key ... because this key is rather large and because expanding it can take maybe five or ten seconds depending, I disallow expanding that key ... here is the code:

Code:

$node = $e.Node

If $node.Text = "HKEY_CLASSES_ROOT"

 $= $System.MessageBox.Show("Expanding HKEY_CLASS_ROOT has been disabled")

 $e.Cancel = 1

 Return

Endif


Basically, for this particular event $e points to a TreeViewCancelEventArgs object, and that object has a Cancel property. Coming into the function the value is set to false (dont cancel the expand). But you can set it to TRUE to cancel it - and thats what is done.

Anways, still working on this "event strategy" - its a wip - Instead of System.Event I would have liked to called it System.EventArgs ... there is a reason why I probably shouldn't call it that but still thinking about it.

Anyways looking for discussion, comments and feedback - positive and negative. Dont be shy about.

BTW - THIS SCRIPT REQUIRES THE VERY LATEST DEV. BUILD

-Shawn



reg.kix
 Description:
Registry Editor (Readonly)

Download
 Filename:  reg.kix
 Filesize:  12.35 KB
 Downloaded:  772 Time(s)

Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Jan 15, 2006 1:42 am    Post subject: Reply with quote

Decided to go with the System.Sender and System.EventArgs property names ... dev build and this script updated to reflect changes.
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sun Jan 15, 2006 1:36 pm    Post subject: Reply with quote

isn't sender a eventArg?
why separate properties?

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Jan 15, 2006 3:12 pm    Post subject: Reply with quote

Your right. Sender "could be" exposed through EventArgs (like you say, it is there, buried under-the-covers), let me think about more.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> KiXforms.NET 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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group