hi,
Antonio thanks for taking care of my problem ....
Yes, i tried this too, but it reports an error
o2:Invoke( "TestConnectionDll", "" )
Just today I intended to send a description of what was happening in the meantime.
On the forum
https://stackoverflow.com/questions/6252334/singleton-com-object-requiredI found the following:
COM does not directly support the Singleton pattern, but it does not strictly prohibit it either. It's just that there's no registry setting that says "always serves the same object." In fact, the standard COM instance mechanism requires that a truly new object be returned each time you call it (this mechanism is used internally by new operators and CreateInstance (). This means that to create a valid COM singleton, you cannot allow your clients to do it themselves all of this can be done, but it is tricky and rarely necessary.
From this I concluded that the classic way of using singleton technology, cannot be achieved by a direct call to GetInstance.
The idea is to add a method, which I will call, internally raising the singleton instance.
I made a test program with c #:
class1.cs
Code: Select all | Expand
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyTest
{
public class Singleton
{
public string GetCardType()
{
return "MoneyBack";
}
public int GetCreditLimit()
{
return 15000;
}
public int GetAnnualCharge()
{
return 500;
}
public string GetCardTypeRet( string ret )
{
//Console.WriteLine("Counter Value " + ret); // due to testing from the console application ....
return ret;
}
}
//---------------------------------------------
public class Car
{
public string GetCardColorRet(string ret)
{
return ret;
}
public object MyFunction(int something = 0, string somethingelse = "zzz") // the arguments are due to future testing
{
var ret = new Singleton();
return ret;
}
public object GetObj() // the method, which I will call, internally raises the singleton instance.
{
SingletonTest fromEmployee = SingletonTest.GetInstance;
return fromEmployee;
}
}
//---------------------------------------------
public sealed class SingletonTest //
{
private static int counter = 0;
/*
* Private property initilized with null
* ensures that only one instance of the object is created
* based on the null condition
*/
private static SingletonTest instance = null;
/*
* public property is used to return only one instance of the class
* leveraging on the private property
*/
public static SingletonTest GetInstance
{
get
{
if (instance == null)
instance = new SingletonTest();
return instance;
}
}
/*
* Private constructor ensures that object is not
* instantiated other than with in the class itself
*/
private SingletonTest()
{
counter++;
//Console.WriteLine("Counter Value " + counter.ToString() + " formirao instancu Singleton"); // due to testing from the console application ....
}
/*
* Public method which can be invoked through the singleton instance !!!
*/
public void PrintDetails(string message) // due to testing from the console application ....
{
//Console.WriteLine(message);
}
// added ... test function !!!
public string GetCardTypeRet(string ret)
{
return ret;
}
public string TestConnectionDLL(string ret)
{
return ret;
}
}
}
olebrow:

Register COM
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /codebase C:\Users\Dubravko\source\repos\MyTest\MyTest\bin\Release\MyTest.dll
prg code:
Code: Select all | Expand
// visible class
o1 := CREATEOBJECT("MyTest.Singleton") // namespace->MyTest public class->Singleton
alert(valtype(o1)) // "O"
alert(o1:GetCardTypeRet("Tu sam 2!!!!!!")) // -> "Tu sam 2!!!!!!"
o2 := CREATEOBJECT("MyTest.Car") //
alert(valtype(o2)) // -> "O"
alert(valtype( o2:GetObj() ) ) // -> "O"
o3 := o2:GetObj() // -> objekt - dignuta instanca
alert( o3:TestConnectionDLL("string_ret") ) // -> "string_ret" the test calls methods from a singleton instance
Now I expect TPS900 terminal vendors to add a method that will internally boot up the singleton instance and try it all out.
Here it is additionally good, which can be solved in this way, to manage the bluetooth port from FWH.
regards
Dubravko Basic
http://www.inteh.hr