Search code examples
delphichilkat

- dcc32 Error- Unit3.pas(79): E2010 Incompatible types: 'PWideChar' and 'WideString'


I received an error - In Delphi XE3 - using chilkat library . This is the error:

[dcc32 Error] Unit3.pas(79): E2010 Incompatible types: 'PWideChar' and 'WideString'

and this is a piece of my code that received this error :

var  
 privKeyXml: PWideChar;  
...  
 privKeyXml := rsa.ExportPrivateKey();   
...  

The ((ExportPrivateKey)) will Export the key in XML format ( As I read in the chilkat website ) How can I fix it ?


Solution

  • ExportPrivateKey() returns a WideString value:

    TChilkatRsa Delphi ActiveX Reference Documentation

    function ExportPrivateKey(): WideString;
    

    You can't assign a WideString to a PWideChar directly, you need to type-cast it, eg:

    var  
     privKeyXml: WideString;  
     privKeyXmlPtr: PWideChar;  
    ...  
     privKeyXml := rsa.ExportPrivateKey();   
     privKeyXmlPtr := PWideChar(privKeyXml);
    ...