Solved

Late binding

Posted on 2004-09-13
14
1,215 Views
Last Modified: 2012-02-23
Hi!

I have the following code that needs to be translated into C#(no problems) and used with late binding(???)
A reference to gbaapi.exe is added in the project.

      Dim oGBA As Object
      Dim RetValue
      'Creates the GBA object
      Set oGBA = CreateObject("GBAAPI.GBA")

      'Specifies the data location of the chosen client
      RetValue = oGBA.SetClientPath("c:\program files\mamut\data\client\000\001")
      If RetValue = 0 Then
          Response = MsgBox("The path to the client data location is incorrect.", 0, "MAMUT API")
      End If

      'Adds the contact object to the GBA object
      Dim oContact
      Set oContact = oGBA.CreateContactObject()
      If TypeName(oContact) <> "Object" Then
              Response = MsgBox("An error occurred during the creation of the Contact object.", 0, "MAMUT API")
      End If

      'Create a new contact
      RetValue = oContact.CreateNew()
      If RetValue = 0 Then
          Response = MsgBox("An error occurred during creation of new contact.", 0, "MAMUT API")
      End If

      'Make changes to a contact (after it is retrieved/created)
      oContact.ContName = "Mamut Ltd"
      oContact.Street = "90 Long Acre"
      oContact.City = "London"
      oContact.Zipcode = "WC2E 9RZ"
      oContact.Data56 = 1

      'Save a contact
      RetValue = oContact.Save()
      If RetValue = 0 Then
          Response = MsgBox("An error occurred during saving of contact.", 0, "MAMUT API")
      End If


I tried this:
      public class Faktura
      {
            public bool CreateFaktura()
            {
                  gbaapi.gba GBA = new gbaapi.gba();
                  if(GBA.setclientpath(@"\\SERVER\Mamut\Data\Client\000\001").ToString()!="0")
                  {      
                        gbaapi.contactClass oContact = (gbaapi.contactClass)GBA.createcontactobject();
                        int RetValue = oContact.createnew();
                        if(RetValue==0)
                        {
                              oContact.contname = "Mamut Ltd";
                              oContact.street = "90 Long Acre";
                              oContact.city = "London";
                              oContact.zipcode = "WC2E 9RZ";
                              oContact.data56 = 1;

                               oContact.save()
                        
                              return true;
                        }
                        else
                              return false;
                  }
                  else
                        return false;
            }
      }

But I keep getting this:
No overload for method 'createnew' takes '0' arguments

public virtual new System.Object createnew ( System.Int32 lnContid )
Member of gbaapi.contactClass

The manual says nothing about create new needs an argument:
Creates a new contact. All properties of the Contact object are now blank (default from the client), except Contid to which the next available number in the number series is assigned. If the requested customer number is already in use, the next available number will be assigned.      

Returns the value 0 if an error occurs; otherwise returns the value 1.

What am I doing wrong?
0
Comment
Question by:aleborg
  • 6
  • 6
14 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 500 total points
ID: 12042757
Try
int RetValue = oContact.createnew(1);

According to the manual, this should work, since "If the requested customer number is already in use, the next available number will be assigned." - so if customer 1 already exists, it will skip and use the next available.

Note that the late-binding interface (IDispatch, which old VB, VBScript etc. used) may be supporting default values or optional parameters, while the normal interface does not (which C# uses).
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12043263
aleborg, thank you for grading the question. But may I ask you to explain what I could have done better to get a higher grade?
0
 

Author Comment

by:aleborg
ID: 12044113
nothing, I was in a hurry and just clicked, sorry :)
0
 

Author Comment

by:aleborg
ID: 12044370
It worked but now I get the error The given transformation is invalid on this row:
gbaapi.contactClass oContact = (gbaapi.contactClass)GBA.createcontactobject();
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12044409
You get this at runtime, not at compile time, right?
0
 

Author Comment

by:aleborg
ID: 12044491
yes
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:AvonWyss
ID: 12044732
What does the manual say about the createcontactobject() method?
0
 

Author Comment

by:aleborg
ID: 12045063
Nothing, but the object browser says:
public virtual new System.Object createcontactobject (  )
    Member of gbaapi.gbaClass

so I tried:
gbaapi.contactClass oContact = (gbaapi.gbaClass)GBA.createcontactobject();
and I get:
Cannot implicitly convert type 'gbaapi.gbaClass' to 'gbaapi.contactClass'

In the VB example they do this:

     Dim oContact
     Set oContact = oGBA.CreateContactObject()
     If TypeName(oContact) <> "Object" Then
             Response = MsgBox("An error occurred during the creation of the Contact object.", 0, "MAMUT API")
     End If

     'Create a new contact
     RetValue = oContact.CreateNew()
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12053719
Apparently, oGBA.CreateContactObject() does not return a contact but rather some object where you need to call CreateNew() to get the actual contact. Could that be?
0
 

Author Comment

by:aleborg
ID: 12054007
That's correct I think, oGBA.CreateContactObject() returns an object where I need to call CreateNew()  to CREATE a new contact but how?
I've tried
object oContact = oGBA.CreateContactObject();
but it don't work
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12054082
Do you have an overview of the different classes and interfaces of this library? Use the Class Explorer to see the different types, and see if one of these has a method called CreateNew().
0
 

Author Comment

by:aleborg
ID: 12054421
gbaapi.contactClass has it:
public virtual new System.Object createnew ( System.Int32 lnContid )
Member of gbaapi.contactClass
That is why I did this:
gbaapi.contactClass oContact = (gbaapi.gbaClass)GBA.createcontactobject();
0
 

Expert Comment

by:cewens
ID: 37637696
i have a problem where i am using dynamic to add a order. i have wcf rest service with the api. but i run the rest service in debug mode it works perfectly but when i deploy it to iis it does not work i get an error in initializing the order. any ideas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Split string on commas but not when enclosed in parentheses 7 48
New to SOAP and need some direction 10 46
Icons and Colors for Terms 3 24
Syntax error 9 45
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now