cancel
Showing results for 
Search instead for 
Did you mean: 

Delphi UserFieldsMD

former_member687054
Participant
0 Kudos

Hi,

I want to create userfields with the di object UserFieldsMD, but I get the error "Ref count for this object is higher then 0".

I've a record set object before and if I don't use a recordset object it's ok, but I really need to use it.

Any Delphi code for this ? (adding userfield in delphi without error)

Thank you for your help

Jodérick

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184566
Active Contributor
0 Kudos

Hi Joderick Picard

SAP only allows one meta data object at a time, so no di api objects should be active when doing meta data operations. Creating userfields is using a metadata object, they do this to mantain data integrity. So the reordset must be closed off before performing the meta data transaction.

In certain cases where you use the recordset, what ever values needed, get them, store them in vb variable and the close the recordset. The continue with meta data operation. here is an example of how i did it once

RS = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

'query to check if column exists

RS.DoQuery("SELECT SysObjects.Name, SysColumns.Name FROM SysColumns INNER JOIN SysObjects ON SysObjects.ID = SysColumns.ID WHERE SysObjects.Name='octr' and SysColumns.Name ='U_Brnch'")

If (RS.RecordCount = 0) Then

'if column does not exist recordcount will be zero

'Here i release the object

System.Runtime.InteropServices.Marshal.ReleaseComObject(RS)

'this next line is not needed, just cautious

RS = Nothing

'function that adds field

AddField("OOPR", "Brnch", "Branch", SAPbobsCOM.BoFieldTypes.db_Alpha, SAPbobsCOM.BoFldSubTypes.st_None, 20)

End If

The above is vb.net example. In delphi just set recordset to nothing/null or release com object. Should work.

Hope this helps

former_member687054
Participant
0 Kudos

Hi,

In delphi I set my object to nil and I have my error again.

Any sample code for releasing the com object in Delphi ?

Thank You

Jodérick

former_member184566
Active Contributor
0 Kudos

Sorry, haven't done sbo programming through delphi. I do not think it is nil. It should be something along "nothing" or "null".

Look in the help files of delphi on how to release com objects, that is your best option.

Hope this helps