Rec = record
case Boolean of
False: (s: array[0..51] of AnsiChar);
True: (i: array[0..12] of Integer);
end;
procedure TForm2.btnCreateStringClick(Sender: TObject);
var
r: Rec;
s: AnsiString;
I: Integer;
code, value: string;
begin
//da stringa a Cardinal
FillChar(r.s, SizeOf(r.s), 0);
s := 'IDontKnowHowToDoItButIHopeYouCanHelpMeEasilyAndSoon';
Move(PAnsiChar(s)^, r.s, Length(s));
for I := Low(r.i) to High(r.i) do
begin
value := IntToStr(not(r.i[I] shl 1));
mmoString.Lines.Add('r.i['+ IntToStr(I) +'] := Cardinal(not ' + value + ') shr 1;');
end;
end;
r.i[0] := Cardinal(not 521606959) shr 1;
r.i[1] := Cardinal(not 933339531) shr 1;
r.i[2] := Cardinal(not 790570805) shr 1;
r.i[3] := Cardinal(not 924924205) shr 1;
r.i[4] := Cardinal(not -1557060819) shr 1;
r.i[5] := Cardinal(not 296035637) shr 1;
r.i[6] := Cardinal(not 765672245) shr 1;
r.i[7] := Cardinal(not 758358295) shr 1;
r.i[8] := Cardinal(not -1592183513) shr 1;
r.i[9] := Cardinal(not 1027022613) shr 1;
r.i[10] := Cardinal(not -1592183529) shr 1;
r.i[11] := Cardinal(not 252786489) shr 1;
r.i[12] := Cardinal(not 924784035) shr 1;
Type
EncodedString=Array of Cardinal;
procedure EncodeString(Str:AnsiString;Var R:EncodedString);
Var
i:integer;
begin
SetLength(R,Length(Str));
for i:=1 to Length(Str) do R[i-1]:=Not(Byte(Str[i]) SHL 1);
end;
procedure DecodeString(const R:EncodedString;Var Str:AnsiString);
Var
i:integer;
begin
SetLength(Str,Length(R));
for i:=1 to Length(Str) do Str[i]:=AnsiChar((Not R[i-1]) SHR 1);
end;
procedure WriteDecodingCode(const StrVarName:String;const Enc:EncodedString);
Var
EncConstArray:String;
i:integer;
begin
if Length(Enc)=0 Then Exit; // prevent errors
mmoString.Lines.Add('DecodeString('+StrVarName+',[');
EncConstArray:='';
for i:=0 to Length(Enc)-1 do EncConstArray:=EncConstArray+IntToStr(Enc[i])+',';
EncConstArray[Length(EncConstArray)]:=']'; // replace last ',' with ']'
mmoString.Lines.Add(EncConstArray+');');
end;
A night of love one never forgets...
procedure WriteDecodingCode(const StrVarName:String;const Enc:EncodedString);
Var
i:integer;
begin
if Length(Enc)=0 Then Exit; // prevent errors
mmoString.Lines.Add('SetLength(EncConst,'+IntToStr(Length(Enc))+');');
for i:=0 to Length(Enc)-1 do
mmoString.Lines.Add(Format('EncConst[%d]=%d',[i,Enc[i]]));
mmoString.Lines.Add('DecodeString(EncConst,'+StrVarName+');');
end;
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
add combobox item based on numbers | 9 | 143 | |
FMX StringGrid1->Canvas->FillR |
3 | 153 | |
Performance of SQL statement | 37 | 111 | |
Why is there a Difference between the SQL String and using the Parameter ? | 7 | 37 |
Join the community of 500,000 technology professionals and ask your questions.