开发者

Dynamic programming in VB

We develop applications for SAP using their SDK. SAP provides a SDK for changing and handling events occuring in the user interface.

For example, with this SDK we can catch a click on a button and do something on the click. This programming can be done either VB or C#.

This can also be used to create new fields on the pre-existing form. We have developed a specific application which allows users to store the definition required for new field in a database table and the fields are created at the run time.

So far, this is good. What we require now is that the user should be able to store the validation code for the field in the database and the same should be executed on the run time.

Following is an example of such an event:

Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
    Dim oForm As SAPbouiCOM.Form
    If pVal.FormTypeEx = "ACC_QPLAN" Then
        If pVal.EventType = SAPbouiCOM.BoEventTypes.et_LOST_FOCUS And pVal.BeforeAction = False Then
            oProdRec.ItemPressEvent(pVal)
        End If
    End If
End Sub

Public Sub ItemPressEvent(ByRef pVal As SAPbouiCOM.ItemEvent)
    Dim oForm As SAPbouiCOM.Form

    oForm = oSuyash.SBO_Application.Forms.GetForm(p开发者_开发问答Val.FormTypeEx, pVal.FormTypeCount)
    If pVal.EventType = SAPbouiCOM.BoEventTypes.et_LOST_FOCUS And pVal.BeforeAction = False Then
        If pVal.ItemUID = "AC_TXT5" Then
            Dim CardCode, ItemCode As String

            ItemCode = oForm.Items.Item("AC_TXT2").Specific.Value
            CardCode = oForm.Items.Item("AC_TXT0").Specific.Value

            UpdateQty(oForm, CardCode, ItemCode)
        End If
    End If
End Sub

So, what we need in this case is to store the code given in the ItemPressEvent in a database, and execute this in runtime.

I know this is not straight forward thing. But I presume there must be some ways of getting these kind of things done.

The SDK is made up of COM components.

Thanks & Regards, Rahul Jain


I've not done this myself, but I think you're going to have to actually use the Systems.Runtime.CompilerServices functions to dynamically compile an assembly and then link it in. Another solution if you are using SQL Server might be to take advantage of the fact that you can write C# or VB.NET code in stored procedures. That might be a way.


Dim sqlstring1 As String = "Blah Blah Blah SQL here"
Dim Rs SAPbobsCOM.Recordset
Rs = GetDIConnection.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
rs.doquery(SqlString1)


You can create the code dynamically and compile it..

Have some simple interfaces to call the validation code and in all your dynamic code, implement the interface(s). This way, you can load assembly dynamically and get the class as an interface and use that interface directly..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜