Problem with using .NET constructor in MapBasic

19 views
Skip to first unread message

Evgeny Kleiman

unread,
Oct 23, 2021, 1:50:49 PM10/23/21
to MapInfo-L
Hello,
I have a DLL written in C# with the following class:
  namespace MapaGisSQL
 {
    public class DAL
   {
         public string server { get; set; }
        public string database { get; set; }
        public string password { get; set; }
        public string username { get; set; }
        public DAL()
        {

        }
        public DAL(string server, string database, string username, string password)
        {
            this.server = server;
            this.database = database;
            this.username = username;
            this.password = password;

        }
   }
}
It means that DAL is a constructor for this class.
I try to use the following code in MapBasic :
  Include "MapBasic.def"
  Declare Sub Main() 

Declare Method New_DAL Class "MapaGisSQL.DAL" Lib
"MapaGisSQL.dll" Alias Ctor_CreateInstance( serverName as string, database as string, username  as string, password as string) as This

Sub Main()
dim serverName as string, database as string, username  as string, password as string
Dim obj as This
serverName = "myserver"
            database = "mydatabase"
            username = "myuser"
            password = "123321"
obj = New_DAL(serverName, database, username, password)
'Then I am going to call some methods of DLL
End Sub

This code passes the compilation. But when I run the code in MapInfo 2019 I get the following message:
Could not find a public, static method named "DAL".  Check method name and signature
I don't understand what wrong. I did exactly as it is described in "mapinfo-mapbasic-v2019-reference.pdf", page 343. 
Any help will be appreciated.
   

Evgeny Kleiman

unread,
Oct 24, 2021, 12:15:54 AM10/24/21
to MapInfo-L
The problem is resolved: I need to add byval:
  Declare Method New_DAL Class "MapaGisSQL.DAL" Lib
"MapaGisSQL.dll" Alias Ctor_CreateInstance( byval serverName as string, byval database as string,
byval username  as string, byval password as string) as This
Reply all
Reply to author
Forward
0 new messages