The CodeRage 4 Sessions & Replays are online.
Tag Archives: Delphi
Detect If my Delphi application is running under a 64-bit version of Windows.
The next code shows how detect If my Delphi application is running under a 64-bit version of Windows.
uses
Windows;
function IsWow64Process: Boolean;
type
TIsWow64Process = function( hProcess: Windows.THandle; var Wow64Process: Windows.BOOL): Windows.BOOL; stdcall;
var
IsWow64Process: TIsWow64Process;
Wow64Process : Windows.BOOL;
begin
Result := False;
IsWow64Process := GetProcAddress(GetModuleHandle(Windows.kernel32), 'IsWow64Process');
if Assigned(IsWow64Process) then
begin
if not IsWow64Process(GetCurrentProcess, Wow64Process) then
Raise Exception.Create('Invalid handle');
Result := Wow64Process;
end;
end;
Using Rijndael Algorithm in Delphi 2007. Net
The next code shows a sample of how use the Rijndael Algorithm in Delphi 2007. Net
uses
System.Security.Cryptography,
System.Text;
type
TDynamicArrayOfByte = array of Byte;
function Encrypt(StrtoEncrypt, PK: string): TDynamicArrayOfByte; // pk, must be of a string of 32 characters
var
miRijndael: Rijndael;
encrypted: TDynamicArrayOfByte;
toEncrypt: TDynamicArrayOfByte;
bytPK: TDynamicArrayOfByte;
i: integer;
begin
Result := nil;
miRijndael := System.Security.Cryptography.RijndaelManaged.Create;
try
toEncrypt := System.Text.Encoding.UTF8.GetBytes(StrtoEncrypt);
bytPK := System.Text.Encoding.UTF8.GetBytes(PK);
miRijndael.Key := bytPK;
miRijndael.GenerateIV;
encrypted := (miRijndael.CreateEncryptor()).TransformFinalBlock(toEncrypt, 0, Length(toEncrypt));
setlength(result, Length(miRijndael.IV) + Length(encrypted));
for i:=0 to Length(miRijndael.IV)-1 do
result[i] := miRijndael.IV[i];
for i:=0 to Length(encrypted)-1 do
result[i + Length(miRijndael.IV)] := encrypted[i];
finally
miRijndael.Clear();
end;
end;
function DesEncrypt(BufferEncrypted: TDynamicArrayOfByte; PK: string): string; // pk, must be of a string of 32 characters
var
miRijndael: Rijndael;
encrypted: TDynamicArrayOfByte;
tempArray: TDynamicArrayOfByte;
bytPK: TDynamicArrayOfByte;
i : integer;
begin
Result := '';
miRijndael := System.Security.Cryptography.RijndaelManaged.Create;
setlength(tempArray, Length(miRijndael.IV));
setlength(encrypted, Length(BufferEncrypted) - Length(miRijndael.IV));
try
bytPK := System.Text.Encoding.UTF8.GetBytes(PK);
miRijndael.Key := bytPK;
for i:=0 to Length(tempArray)-1 do
tempArray[i] := BufferEncrypted[i];
for i:=0 to Length(encrypted)-1 do
encrypted[i] := BufferEncrypted[i + Length(tempArray)];
miRijndael.IV := tempArray;
Result := System.Text.Encoding.UTF8.GetString((miRijndael.CreateDecryptor()).TransformFinalBlock(encrypted, 0, Length(encrypted)));
finally
miRijndael.Clear();
end;
end;
How to mark all the instances of a word in a TRichEdit using Delphi
the Nect code shows how to mark all the instances of a word in a TRichEdit using Delphi
procedure MarkString(RichEdit:TRichEdit;const strtomark : string);
Var
FoundAt : integer;
begin
FoundAt:=RichEdit.FindText(strtomark,0,maxInt,[stWholeWord]);
while FoundAt <> -1 do
begin
RichEdit.SelStart := FoundAt;
RichEdit.SelLength := Length(strtomark);
RichEdit.SelAttributes.Style := [fsBold];
RichEdit.SelAttributes.Color := clRed;
RichEdit.SelText :=strtomark;
FoundAt:=RichEdit.FindText(strtomark,FoundAt + length(strtomark),maxInt,[stWholeWord]);
end;
end;
procedure UnMarkString(RichEdit:TRichEdit;const strtomark : string);
Var
FoundAt : integer;
begin
FoundAt:=RichEdit.FindText(strtomark,0,maxInt,[stWholeWord]);
while FoundAt <> -1 do
begin
RichEdit.SelStart := FoundAt;
RichEdit.SelLength := Length(strtomark);
RichEdit.SelAttributes.Style := [];
RichEdit.SelAttributes.Color := clBlack;
RichEdit.SelText :=strtomark;
FoundAt:=RichEdit.FindText(strtomark,FoundAt + length(strtomark),maxInt,[stWholeWord]);
end;
end;
MarkString(RichEdit1,'delphi'); //To Mark a string
UnMarkString(RichEdit1,'delphi'); //To UnMark a string
List of changes between versions of Delphi (What’s New)
In response to this question asked in stackoverflow leave here a list of changes between versions of Delphi.
- What’s New in Delphi 5
- What’s New in Delphi 6
- What’s New in Delphi 7
- What’s New in Delphi 2005
- What’s New in Delphi 2006
- What’s New in Delphi 2007
- What’s New in Delphi 2009
- What’s New in Delphi 2010
- What’s New in Delphi XE
- What’s New in Delphi XE2
Others
Bye.