I have a question regarding OLE and Widestring type.
I am creating OLE object, then calling some method with parameters, something like that:
var ole: OleVariant;
sParameter:String;
...
sParameter:='test_string';
ole := CreateOLEObject('...ole object...');
ole.SomeFunction(sParameter);
And this doesn't work well.
If instead of variable I use literal string then it works fine:
ole.SomeFunction('test_string');
I made it working by declaring widestring variable and use it like this:
wsParameter:Widestring;
...
wsParameter:=sParameter;
...
ole.Somefunction(wsParameter);
My question is: Is there a simpler way to use "String" type variable to call OLE method? I tried casting, without luck:
ole.Somefunction(WideString(sParameter));
And here (
https://wiki.freepascal.org/Widestring) it says that correct way is to use UTF8ToUTF16 function from LazUTF8, I tried like that and it doesn't work either (I get SIGSEGV exception):
ole.Somefunction(UTF8ToUTF16(sParameter));
I have this string variable declared elsewhere, and I use it in multiple places in program so I don't want to declare it as a Widestring in a first place - I need to convert it before calling OLE method.