4

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!

1 Answer 1

7

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));
  ..
Sign up to request clarification or add additional context in comments.

1 Comment

What unit are the functions DecodeBase64 and EncodeBase64 declared in?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.