WebView4Delphi icon indicating copy to clipboard operation
WebView4Delphi copied to clipboard

Parameter OleVariant type in dynamic link library

Open sxmxta opened this issue 11 months ago • 1 comments

@salvadordf Hello, I am the author of the energy open source framework and previously wrapped a set of underlying libraries in Golang using Lazarus CEF4Delphi. Now I have also used Golang to encapsulate a complete set of dynamic link libraries based on Lazarus WebView4Delphi. I have a question, I in the class: "TWVBrowserBase, TCoreWebView2," function "AddHostObjectToScript, AddHostObjectToScriptWithOrigins" The parameter "object_: OleVariant" in these functions. At this point I am not familiar with the "OleVariant" type and do not know how to use such a parameter passed in a dynamic library. Can you give me some suggestions for reference? I call this dynamic library API in Golang. Can I create a generic class wrapper "OleVariant "type in Lazarus to use? Can you give me some hints.

Thank you very much.

sxmxta avatar Mar 04 '24 06:03 sxmxta

Hi,

The documentation for those methods can be found here :

As you can see, Delphi converts a VARIANT parameter to OleVariant when you import the WebView2.tlb file found in the WebView2 NuGet package.

Read these pages to know more about the OleVariant type and the Variant types.

OleVariant

The main difference between Variant and OleVariant is that Variant can contain data types that only the current application knows what to do with. OleVariant can only contain the data types defined as compatible with OLE Automation, which means the data types that can be passed between programs or across the network without worrying about whether the other end will know how to handle the data.

When you assign a Variant that contains custom data (such as a Delphi string, or one of the new custom variant types) to an OleVariant, the runtime library tries to convert the Variant into one of the OleVariant standard data types (such as a Delphi string converts to an OLE BSTR string). For example, if a variant containing an AnsiString is assigned to an OleVariant, the AnsiString becomes a WideString. The same is true when passing a Variant to an OleVariant function parameter.

This StackOverflow answer might be what you're looking for.

salvadordf avatar Mar 04 '24 16:03 salvadordf

Thank you very much. I'm going to learn them

sxmxta avatar Mar 05 '24 01:03 sxmxta