Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips > Official Updates
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Official Updates Updates to official libraries could be found here.
This forum is only available to licensed users.


Door library (Beta) - Special library


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2008, 12:25 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,633
Default Door library (Beta) - Special library

Edit: Door library v1.0 is included in Basic4ppc v6.30.
Edit: Door library v0.9 is released. Thanks to Agraham it now supports events.

The Door library is a special library.
It allows you to access .Net objects, methods and properties from Basic4ppc code without creating new libraries.
It won't replace any existing library but rather make these libraries and Basic4ppc itself more complete.
For example you can use this library to access all the properties of a control (on the desktop or device) and not only the subset supported by Basic4ppc.

You should have some knowledge with the .Net Framework if you want to fully exploit this library.
However I hope that in the future many examples and solutions will be available on the forum for everyone to use.

This is a beta version and it doesn't yet include a proper manual.

The Door library includes three types of objects:

Object:

Holds a reference to an existing or a new .Net object.
CreateNew (Type As String) - Creates a new static or instance object. No arguments are passed to the constructor.
CreateNew2 (Type As String, Args As Object()) - Creates a new instance object. Passes the objects array to the constructor.
FromControl (Control As Control) - Gets a reference to a Basic4ppc intrinsic control.
FromLibrary (ObjectName As String, FieldName As String, B4PObject2) - Gets a reference to an object which was added from an external library.
You should only use this method if the object does not expose a reference (usually with Value or ControlRef). FieldName must be known.
GetProperty (Property As String) As Object - Returns the value of the object's specified property.
GetProperty2 (Property As String, Index As Int32) As Object - Returns the value of an indexed property.
New1 (InitializeDataGrid As Boolean) - Initializes the Object control.
InitializeDataGrid should be set to true if you are using the object with a Table control.
RunMethod (Method As String) As Object- Runs a method without any arguments.
RunMethod2 (Method As String, Arg1 As String, Type1 As String) As Object- Runs a method with one argument. The argument cannot be an object.
RunMethod3 (Method As String, Arg1 As String, Type1 As String, Arg2 As String, Type2 As String) As Object - Runs a method with two arguments. Arguments cannot be objects.
RunMethod4 (Method As String, Args As Object()) As Object - Runs a method with any number and type of arguments.
SetProperty (Property As String, Value As String) - Sets the value of the specified property. Value cannot be an object.
SetProperty2 (Property As String, Value As Object) - Sets the value of the specified property. Value is an object.
SetProperty3 (Property As String, Value As String, Index As Int32) - Sets the value of the specified indexed property. Value cannot be an object.
SetProperty4 (Property As String, Value As Object, Index As Int32) - Sets the value of the specified indexed property. Value is an object.
System_NS, System_Data, System_Drawing, System_Windows_Forms, System_Windows_Forms_Datagrid - Returns the fully qualified named of these assemblies. System_Windows_Forms_Datagrid will only be set if at least one of the objects was initialized with New1(true).
Value - Gets or sets a reference to the object.

ObjectArray

ObjectArray is mostly used to pass arguments to constructors or methods.
Get (Index As Int32) As Object - Returns the object in the specified index.
New1 (Size As Int32) - Initializes the array to the specified size.
SetObject (Index As Int32, Object As Object) - Sets the value of the specified index. The value is an object.
SetValue (Index As Int32, Value As String, Type As String) - Sets the value of the specified index. Value cannot be an object.
Value - Gets or sets a reference to the ObjectsArray.

Event

Event objects allow you to catch miscellaneous events.
The following types of events handlers are supported:
- EventHandler
- KeyEventHandler
- KeyPressEventHandler
- MouseEventHandler
- PaintEventHandler

Data - Returns an object which holds the EventArgs object.
Dispose - Frees the resources of the Event object and removes the event handler.
New1 (Object As Object, Event As String) - Wires the event sub to the specified object and specified event. See the following examples.
NewEvent Event - The event that will be raised.

Examples:
Change the Form's KeyPreview property to true - All keystrokes will be first handled by Form_KeyPress event:
Form1 is a regular Form, ofrm is an Object
Code:
Sub App_Start
    Form1.Show
    ofrm.New1(false)
    ofrm.FromControl("Form1")
    ofrm.SetProperty("KeyPreview",true)
End Sub
Desktop only: Change the icon of a specific form.
Form1 is a regular Form, ofrm and oIcon are Objects, args is an ObjectArray.
Code:
Sub App_Start
    Form1.Show
    ofrm.New1(false)
    oIcon.New1(false)
    ChangeIcon("Form1",AppPath & "\SomeIcon.ico")
    'ChangeIcon("Form2",AppPath & "\AnotherIcon.ico")
End Sub

Sub ChangeIcon (FormName, IconFile)
    ofrm.FromControl(FormName)
    args.New1(1)
    args.SetValue(0,IconFile,"System.String")
    oIcon.CreateNew2("System.Drawing.Icon" & oIcon.System_Drawing, args.Value)
    ofrm.SetProperty2("Icon",oIcon.Value)
End Sub
Set the WebRequest Referer header's value.
WebRequest1 is a WebRequest object (HTTP library), obj is an Object.
Code:
Sub App_Start
    WebRequest1.New1("http://www.basic4ppc.com")
    obj.New1(false)
    obj.FromLibrary("WebRequest1","req",B4PObject(2))
    obj.SetProperty("Referer","http://xxx.xxx.xx")
    'Msgbox(obj.GetProperty("Referer"))
End Sub
Passing color value.
Code:
 Sub App_Start
    Form1.Show
    clr.New1(false)
    txt.New1(false)
    txt.FromControl("textbox1")
    clr.CreateNew("System.Drawing.Color" & clr.System_Drawing)
    txt.SetProperty2("BackColor",clr.RunMethod2("FromArgb",cRed,"System.Int32")) 'Use Color.FromArgb(Int32) to pass the color
End Sub
Events examples:
Handle the TextChanged event (fires whenever the text changes):

Code:
'obj is an Object, TextBox1ChangedEvent is an Event.
Sub App_Start
    Form1.Show
    obj.New1(false)
    obj.FromControl("textbox1")
    TextBox1ChangedEvent.New1( obj.Value,"TextChanged")
End Sub

Sub TextBox1ChangedEvent_NewEvent
    form1.Text = textbox1.Text
End Sub
Show which mouse button was pressed:
Code:
obj and o are Objects, MouseDownEvent is an Event.
Sub App_Start
    Form1.Show
    obj.New1(false)
    o.New1(false)
    obj.FromControl("form1")
    MouseDownEvent.New1( obj.Value,"MouseDown")
End Sub

Sub MouseDownEvent_NewEvent
    o.Value = MouseDownEvent.Data 'Get the event's data.
    form1.Text = o.GetProperty("Button") 'Returns Left, Middle or Right
End Sub
Attached Files
File Type: zip Door-0.9.zip (4.0 KB, 141 views)

Last edited by Erel : 04-04-2008 at 09:49 AM. Reason: Updated version - 0.9
Reply With Quote
  #2 (permalink)  
Old 03-26-2008, 02:39 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

This supercedes my ControlProperties library and is much more powerful.

Can I point out a typo in one of the method signatures :-

RunMethod (Method As String) As Object - Runs a method without any arguments.
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 03:02 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,633
Default

Thanks agraham.
Reply With Quote
  #4 (permalink)  
Old 03-26-2008, 03:04 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

After a closer look I have a query.
Quote:
FromControl (Control As Control) - Gets a reference to a Basic4ppc intrinsic control.
I assume this is also used if the library object does expose a reference (usually with Value or ControlRef).
Quote:
FromLibrary (ObjectName As String, FieldName As String, B4PObject2) - Gets a reference to an object which was added from an external library. You should only use this method if the object does not expose a reference (usually with Value or ControlRef). FieldName must be known.
I am probably being thick but I don't understand what FieldName might be? The only thing that I can think of is that it is the instance variable that most such libraries load with a new instance of whatever object they are instantiating, in which case I assume this variable would have to be Public to work!
Reply With Quote
  #5 (permalink)  
Old 03-26-2008, 03:18 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

I didn't really mean to generate this much traffic but there isn't a System_NS property in the library! Which assembly is it meant to reference? I don't know of one called System.NS.
Reply With Quote
  #6 (permalink)  
Old 03-26-2008, 03:18 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,633
Default

If the library exposes a reference then you should use: obj.Value = bar.ControlRef, although obj.FromControl(bar.ControlRef) will also work.

FieldName is the instance variable that holds the .Net object in many libraries.
Your assumption is logical but not correct. You can access private fields with Reflection. A little but strange, I agree.
Reply With Quote
  #7 (permalink)  
Old 03-26-2008, 03:21 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,633
Default

I hope to see a lot of traffic around this library as it is really an interesting one

Download the attached file again. The first uploaded file didn't include it.
System_NS stands for System.dll.
It didn't behave properly when it was named System.
Reply With Quote
  #8 (permalink)  
Old 03-26-2008, 03:53 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

More traffic! - CASE-SENSITIVITY!

If anyone else is playing with this library, like I am, it might save a bit of frustration to know that, unlike Basic4PPC, the Method and Property names passed to this library are case-sensitive and so must be the exact .NET name or an exception will occur. e.g TabIndex not tabindex or tabIndex etc.
Reply With Quote
  #9 (permalink)  
Old 03-26-2008, 06:24 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

I was experimenting to see if I really needed a fully qualified Assembly name for CreateNew2.

I can successfully make a DirectoryInfo object and invoke a method using just the assembly name for mscorlib.
Code:
ofrm.CreateNew2("System.IO.DirectoryInfo,mscorlib", args.Value)
Msgbox(ofrm.RunMethod("ToString"))
But if I try, slightly modified from a sample
Code:
oIcon.CreateNew2("System.Drawing.Icon,System.Drawing", args.Value)
I get a "Could not load file or assembly 'System.Drawing" error. Any idea why the difference Erel?

EDIT :- Note that, undocumented in Erel's first post, you do get the return value of a RunMethod call - I'll wait and see what happens for some of the more esoteric returned objects

Last edited by agraham : 03-26-2008 at 06:34 PM.
Reply With Quote
  #10 (permalink)  
Old 03-26-2008, 06:47 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,208
Awards Showcase
Forum Contributer 
Total Awards: 1
Default TabIndex example

The hoary old TabIndex problem.

Put the control names in an arraylist (or array) in the tab order you want
Code:
 For i = 0  To CtlArray.Count - 1
   Obj1.FromControl( CtlArray.Item(i) )
   Obj1.SetProperty ("TabIndex",  i )
Next
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging Outlook library and Phone library Erel Official Updates 2 07-14-2008 03:38 PM
load textfile with special characters (äöü) bob Questions & Help Needed 2 11-19-2007 01:24 PM
New serial library - beta version Erel Announcements 13 08-02-2007 12:24 PM
Special Folders on PC BPak Questions & Help Needed 2 06-01-2007 09:53 PM


All times are GMT. The time now is 01:03 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0