codeface

Software.Design

Archive for the ‘Source Code’ Category

 

Delphi Code to Restart Your Own Application

January 20th, 2009

The user of your application needs do close and open it again everytime he/she set a particular configuration to make this change available. So, with the code below You can give the possibility to your users a quick restart and improve the experience of your software. Simple task: Create a batch file with the filename [...]

Read full article | No Comments »

Delphi Code to Convert Bitmap to Grayscale

September 11th, 2008

Every picture that You insert into your delphi application project makes the executable bigger. So, If you want minimize that problem with your disabled images of your buttons, You could use the code below: function ConvertBitmapToGrayscale(const Bitmap: TBitmap): TBitmap; var i, j: Integer; Grayshade, Red, Green, Blue: Byte; PixelColor: Longint; begin with Bitmap do for [...]

Read full article | No Comments »

Delphi Code to Simple Bitmap Encryption

August 30th, 2008

The Code below shuflle the bits of the image using the key to define differents ways to encrypt the same bitmap. procedure EncryptBitmap(const Bmp: TBitmap; Key: Integer); var   BytesPorScan: Integer;   w, h: integer;   p: pByteArray; begin   try BytesPorScan := Abs(Integer(BMP.ScanLine[1]) – Integer(BMP.ScanLine[0]));   except raise Exception.Create(‘Error’);   end;   RandSeed := Key; [...]

Read full article | No Comments »

Delphi Code to Simple Encrypt and Decrypt String

August 28th, 2008

A simple way to encrypt your strings into Delphi Development. The acode below shuffle the characters based on those C1 and C2 constants and You can set to any number to them, but remenber to use the same in both code encryption. function EncryptStr(const S: String; Key: Word): String; var I: Integer; const C1 = 53761;       C2 = [...]

Read full article | No Comments »

Delphi Code to Convert String to Character

August 2nd, 2008

A useful code that convert a string to a character. It’s simple, a string is an array of characters, so you just have to “take” the position you want.Code Below: function StrToChr(Str: string; Pos: Integer): Char; beginResult := Str[Pos]; end;

Read full article | No Comments »

Delphi Code to force delete directory and its content

August 2nd, 2008

When you want to be sure all content of a directory will be deleted, you have to use a recursive procedure to delete every file into a folder before delete the folder itself.Code below: procedure ForceDeleteDirContent(dir: string); var i: integer; sDirectory: string; sr: TSearchRec; beginsDirectory := IncludeTrailingPathDelimiter( dir ); i := FindFirst( sDirectory+’*.*’,faAnyFile,sr ); while [...]

Read full article | No Comments »