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
Desktop only: Change the icon of a specific form.
Form1 is a regular Form, ofrm and oIcon are Objects, args is an ObjectArray.
Set the WebRequest Referer header's value.
WebRequest1 is a WebRequest object (HTTP library), obj is an Object.
Passing color value.
Events examples:
Handle the TextChanged event (fires whenever the text changes):
Show which mouse button was pressed:
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
B4X:
Sub App_Start
Form1.Show
ofrm.New1(false)
ofrm.FromControl("Form1")
ofrm.SetProperty("KeyPreview",true)
End Sub
Form1 is a regular Form, ofrm and oIcon are Objects, args is an ObjectArray.
B4X:
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
WebRequest1 is a WebRequest object (HTTP library), obj is an Object.
B4X:
Sub App_Start
WebRequest1.New1("http://www.b4x.com")
obj.New1(false)
obj.FromLibrary("WebRequest1","req",B4PObject(2))
obj.SetProperty("Referer","http://xxx.xxx.xx")
'Msgbox(obj.GetProperty("Referer"))
End Sub
B4X:
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
Handle the TextChanged event (fires whenever the text changes):
B4X:
'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
B4X:
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
Attachments
Last edited: