I have a declared variable in my code like so:
Var
VarName:Array[0..693] of Byte = ( and my array here );
I have EncdDecd in my uses..
I am looking to encode this Array of Byte into a base64 string using the EncodeBase64 function in EncdDecd.pas
But I am unsure of how to return it into a nice and pretty b64 string that can be converted directly back into a byte array with DecodeBase64...
I have tried a few different approaches..
Var Res:PWideChar;
begin
StringToWideChar(EncodeBase64(@VarName, 693), Res, 693);
ClipBoard.SetTextBuf(Res);
end;
Access Violation with that code...
Also tried:
begin
ClipBoard.SetTextBuf(PWideChar(EncodeBase64(@VarName, 693)));
end;
Which returns a string full of distorted Chinese symbols....
Any help on returning this string would be greatly appreciated..
Thanks!
The functions are declared as
function DecodeBase64(const Input: AnsiString): TBytes;
function EncodeBase64(const Input: Pointer; Size: Integer): AnsiString;
so all you need in Unicode Delphi's is to cast AnsiString to string,
var S: string;
begin
S:= string(EncodeBase64(@VarName, 693));
..
to decode S you should cast it to AnsiString:
var B: TBytes;
begin
B:= DecodeBase64(AnsiString(S));
..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With