salvadordf / WebView4Delphi

WebView4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows.
https://www.briskbard.com/forum/
MIT License
280 stars 56 forks source link

Parameter OleVariant type in dynamic link library #52

Closed sxmxta closed 6 months ago

sxmxta commented 6 months ago

@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.

salvadordf commented 6 months ago

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.

sxmxta commented 6 months ago

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