Please try this:
local o1 := CreateObject( "PaymentService.BluetoothConnector" )
local o2 := TOleAuto():New( o1:Invoke( "GetInstance" ) )
ActiveX - CREATEOBJECT and singleton pattern
- Antonio Linares
- Site Admin
- Posts: 42510
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Re: ActiveX - CREATEOBJECT and singleton pattern
////////////////////////////////////////////
o1 := CreateObject( "PaymentService.BluetoothConnector" )
o2 := TOleAuto():New( o1:Invoke( "GetInstance" ) )
MsgInfo( ValType( o1 ) ) // -> "O"
MsgInfo( ValType( o2 ) ) // -> "O"
////////////////////////////////////////////
o1 := CreateObject( "PaymentService.BluetoothConnector" )
o2 := TOleAuto():New( o1:Invoke( "GetInstance" ) )
MsgInfo( ValType( o1 ) ) // -> "O"
MsgInfo( ValType( o2 ) ) // -> "O"
////////////////////////////////////////////
- Antonio Linares
- Site Admin
- Posts: 42510
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Re: ActiveX - CREATEOBJECT and singleton pattern
> oPOS := CREATEOBJECT("BluetoothConnector.GetInstance('TestConnectionDLL()' ) or something ?
o2 should be the oPOS you were looking for
o2 should be the oPOS you were looking for
Re: ActiveX - CREATEOBJECT and singleton pattern
Ok, i'll try to call TestConnectionDLL with an argument ...
I will report the result ...
I will report the result ...
Re: ActiveX - CREATEOBJECT and singleton pattern
Greeting,
I was away for a while.
If an o2 instance is called from BluetoothConnector,
How to call the TestConnectionDll method eg:
ret: = o2: TestConnectionDll ("") // -> error
ret: = o2: BluetoothConnector: TestConnectionDll ("") // -> error
In other words, no matter how I try to call the method, I get an error. I'm probably wrong in syntax.
Does anyone have an idea how to call a certain method?
Antonio, thanks for the prior help.
![Image](http://www.inteh-app.com/app/ActiveX_scr6.png)
I was away for a while.
If an o2 instance is called from BluetoothConnector,
How to call the TestConnectionDll method eg:
ret: = o2: TestConnectionDll ("") // -> error
ret: = o2: BluetoothConnector: TestConnectionDll ("") // -> error
In other words, no matter how I try to call the method, I get an error. I'm probably wrong in syntax.
Does anyone have an idea how to call a certain method?
Antonio, thanks for the prior help.
![Image](http://www.inteh-app.com/app/ActiveX_scr6.png)
- Antonio Linares
- Site Admin
- Posts: 42510
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Re: ActiveX - CREATEOBJECT and singleton pattern
Please try using:
o2:Invoke( "TestConnectionDll", "" )
o2:Invoke( "TestConnectionDll", "" )
Re: ActiveX - CREATEOBJECT and singleton pattern
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-required
I found the following:
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
olebrow:
![Image](http://www.inteh-app.com/app/sl22.png)
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:
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
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-required
I 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:
![Image](http://www.inteh-app.com/app/sl22.png)
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