OLE and Widestring lazarus / 34-Windows ---------------------------------------------------------------------- dseligo · 2020-11-21 16:06 I have a question regarding OLE and Widestring type. I am creating OLE object, then calling some method with parameters, something like that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ole.SomeFunction('test_string'); I made it working by declaring widestring variable and use it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. ---------------------------------------------------------------------- PascalDragon · 2020-11-21 20:20 Turns out that most of the problems you have (likely) seen where due to a buggy implementation of the parameter dispatching. I have now fixed this in trunk (revisions 47516-47519). If you'd please check whether it works correctly there it would be great and I'd merge that back to 3.2.1 then (so that it will be in the upcoming 3.2.2). As a workaround (in 3.2.0 and older) you should indeed best use WideString variables. ---------------------------------------------------------------------- dseligo · 2020-11-23 10:41 Thanks for help. It is somewhat better but it isn't solved yet. I enabled DEBUG_COMDISPATCH in ComObj.pas. This is test program I used: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program proba;uses ComObj, Variants; { $define ws} var ole: OleVariant;    sPar1,sPar2,sPar3,sPar4,sPar5,sPar6,sPar7:{$ifdef ws}WideString{$else}String{$endif}; begin  sPar1:='FISKAL 4';  sPar2:='98765432109';  sPar3:='19.11.2020 09:09:32';  sPar4:='100';  sPar5:='P1';  sPar6:='333';  sPar7:='99.99';   ole := CreateOLEObject( 'Raverus.FiskalizacijaDEV.COM.CentralniInformacijskiSustav');  WriteLn (ole.ZastitniKodIzracun(sPar1,sPar2,sPar3,sPar4,sPar5,sPar6,sPar7));  VarClear(ole);end. This is the output when parameters are WideString: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ComObjDispatchInvoke calledComObjDispatchInvoke: @CallDesc = $0044004C CallDesc^.ArgCount = 7SearchIDs: Searching 1 IDsSearchIDs: Original name: ZastitniKodIzracun Len: 18SearchIDs: Translated name: ZastitniKodIzracunSearchIDs: GetIDsOfNames result = 00000000SearchIDs: ID[0] = 1610743821DispatchInvoke: Got 7 arguments   NamedArgs = 0DispatchInvoke: Params = 0145FF1CDispatchInvoke: Got ref argument with type = 8 Value = 99.99DispatchInvoke: Params = 0145FF20DispatchInvoke: Got ref argument with type = 8 Value = 333DispatchInvoke: Params = 0145FF24DispatchInvoke: Got ref argument with type = 8 Value = P1DispatchInvoke: Params = 0145FF28DispatchInvoke: Got ref argument with type = 8 Value = 100DispatchInvoke: Params = 0145FF2CDispatchInvoke: Got ref argument with type = 8 Value = 19.11.2020 09:09:32DispatchInvoke: Params = 0145FF30DispatchInvoke: Got ref argument with type = 8 Value = 98765432109DispatchInvoke: Params = 0145FF34DispatchInvoke: Got ref argument with type = 8 Value = FISKAL 4DispatchInvoke: MethodID: 1610743821 InvokeKind: 3f9990122fd1b5fb0abe6bd43b54f94b6 And this is output when parameters are declared as String: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ComObjDispatchInvoke calledComObjDispatchInvoke: @CallDesc = $0044004C CallDesc^.ArgCount = 7SearchIDs: Searching 1 IDsSearchIDs: Original name: ZastitniKodIzracun Len: 18SearchIDs: Translated name: ZastitniKodIzracunSearchIDs: GetIDsOfNames result = 00000000SearchIDs: ID[0] = 1610743821DispatchInvoke: Got 7 arguments   NamedArgs = 0DispatchInvoke: Params = 0145FF1CDispatchInvoke: Got argument with type 8 Value = 100DispatchInvoke: Params = 0145FF20DispatchInvoke: Got argument with type 8 Value = 100DispatchInvoke: Params = 0145FF24DispatchInvoke: Got argument with type 8 Value = 100DispatchInvoke: Params = 0145FF28DispatchInvoke: Got argument with type 8 Value = 100DispatchInvoke: Params = 0145FF2CDispatchInvoke: Got argument with type 8 Value = ZastitniKodIzracunDispatchInvoke: Params = 0145FF30DispatchInvoke: Got argument with type 8 Value = FISKAL 4DispatchInvoke: Params = 0145FF34DispatchInvoke: Got argument with type 8 Value = FISKAL 4DispatchInvoke: MethodID: 1610743821 InvokeKind: 3561d46a69e250b902276864552986b40 I couldn't find where "CallDesc" and "Params" are initially set, and I suspect the problem is there. One more thing. At the beginning of the procedure ComObjDispatchInvoke 3rd parameter was still '19.11.2020 09:09:32', but after call to the SearchIDs procedure it was changed to 'ZastitniKodIzracun'. I can give you needed dll's if you are willing to further debug this problem. ---------------------------------------------------------------------- PascalDragon · 2020-11-23 22:01 Quote from: dseligo on November 23, 2020, 11:41:53 amThanks for help. It is somewhat better but it isn't solved yet. I enabled DEBUG_COMDISPATCH in ComObj.pas. This is test program I used: Add {$mode objfpc}{$H+} at the top. By default FPC uses String = ShortString and those indeed don't work. (I've tested your code and I can reproduce your findings only with ShortStrings) ---------------------------------------------------------------------- dseligo · 2020-11-24 01:40 You are right, that was the problem. These are results with those compiler directives: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ComObjDispatchInvoke calledComObjDispatchInvoke: @CallDesc = $0044004C CallDesc^.ArgCount = 7SearchIDs: Searching 1 IDsSearchIDs: Original name: ZastitniKodIzracun Len: 18SearchIDs: Translated name: ZastitniKodIzracunSearchIDs: GetIDsOfNames result = 00000000SearchIDs: ID[0] = 1610743821DispatchInvoke: Got 7 arguments   NamedArgs = 0DispatchInvoke: Params = 0145FF1CTranslating var ansistring argument 99.99DispatchInvoke: Params = 0145FF20Translating var ansistring argument 333DispatchInvoke: Params = 0145FF24Translating var ansistring argument P1DispatchInvoke: Params = 0145FF28Translating var ansistring argument 100DispatchInvoke: Params = 0145FF2CTranslating var ansistring argument 19.11.2020 09:09:32DispatchInvoke: Params = 0145FF30Translating var ansistring argument 98765432109DispatchInvoke: Params = 0145FF34Translating var ansistring argument FISKAL 4DispatchInvoke: MethodID: 1610743821 InvokeKind: 3f9990122fd1b5fb0abe6bd43b54f94b6 ---------------------------------------------------------------------- PascalDragon · 2020-11-24 12:36 Quote from: dseligo on November 24, 2020, 02:40:13 amYou are right, that was the problem. Okay, then I'll make sure that the fixes I've done are merged to 3.2.1 so that they'll be in 3.2.2.