cancel
Showing results for 
Search instead for 
Did you mean: 

Forms.Item throws exception InvalidForm

Former Member
0 Kudos

Hi,

Please forgive my very first steps with SDK. I have a case where I call

SAPbouiCOM.Form fFAR = appSBO.Forms.Item("svcFAR");

to check if the form already exists. However, instead of null (the first time it doesn't exist), it throws an exception named 'Form - Invalid Form'...

Is this the correct way of checking if a Form already exists? I guess it should return 'null' instead...

Thanks,

Leo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try something like this

       Dim strUniqueID as String = "svcFAR"
        Try
            oForm = SBO_Application.Forms.Item(strUniqueID)
            oForm.Select()
        Catch ex As Exception
            Dim fcp As SAPbouiCOM.FormCreationParams
            fcp = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
            fcp.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed
            fcp.FormType = strFormType
            'fcp.ObjectType = 
            fcp.UniqueID = strUniqueID
            fcp.XmlData = loadFromXML(strXMLFile) 'function provided in SDK Samples
            oForm = SBO_Application.Forms.AddEx(fcp)
         End Try

Be sure to be looking for the correct form name. Sometimes you don't see it's name on the taskbar but the type.

Former Member
0 Kudos

Can't believe something like 'Exists' was not implemented... or GetByKey, or similar..

anyway, I am following the try/catch approach...

But, I wanted to try also something like removing the form and creating it everytime (don't mind the overhead)... However, I can't find the RemoveEx???

form.Remove ("myForm")

... [createparams and stuff]

form.AddEx("myForm")

Is any way of removing the form so this can work?

Regards,

Leo

Former Member
0 Kudos

Well

You could try the .GetForm method. If you know the oForm.Type then you could get it by its instance.

Set oForm = oApplication.Forms.GetForm(MY_FORM_TYPE, i)

And then you could simply close it , oForm.Close().

Check the SAP SDK Help Center, there's a bit of more information.

hope it helps

Answers (1)

Answers (1)

former_member201110
Active Contributor
0 Kudos

Hi Leonardo,

As there is no Exists property of the Forms collection, there is no immediate way to tell if a particular form is open. When dealing with my own forms (ie user forms which can only have one instance open), I use the following procedure to iterate through the forms collection. If the form is not found then I return null:

private SAPbouiCOM.Form SearchForm(string sType) 
{
	SAPbouiCOM.Form oForm;

	for(int i = 0 ; i <= _sboApp.Forms.Count - 1; i++)
	{
		oForm = _sboApp.Forms.Item(i);
		if (oForm.TypeEx == sType) return oForm;
	}
	return null;
}

Kind Regards,

Owen