Sample Delphi CodeSample Delphi Code

I found that I was repeatedly writing the same pieces of code into different routines. So I created a small Unit file called SUtils.pas that can be included in the Uses section of any Pascal Unit (All code works with Delphi 4 and 7 but has not been tested on any other versions)..

GetFileSize
This function determines the the size (in bytes) of a selected file. Useful for reading binary files, etc.
View SourceShow Source...

FileDateTime
This function returns the date and time that the DOS file was created. Useful for updating older files in an installation or for time disabled shareware, etc.
View SourceShow Source...

HasAttr
This function returns a true or false as to whether the selected file has the "Archive", "System", "Hidden" or "Read Only" flags set against it.
View SourceShow Source...

CopyFile
This function uses the "FileRead" and "FileWrite" Delphi functions to copy a file in a binary format. The code that actually does the copying is fairly simple. When a file is opened the file pointer is set to the first byte in the file. The function then reads a block of bytes, in this case 2,048 bytes, and automatically sets the pointer to byte 2,049, ready for the next block of bytes to be read. The information that is read from the file is stored in a block of memory and a pointer to the address of the first byte of that memory block is held in the CopyBuffer pointer, GetMem allocates the space in memory and FreeMem releases that block of memory back to the system.
View SourceShow Source...

MoveFile
This function uses the CopyFile function described above, but deletes the original file after the copy has been completed.
View SourceShow Source...

StrFill
This function allows the programmer to specify then length of a given string, specify the filler character and the alignment of the information within the string. This is useful for column spacing in reports (using fixed length fonts).
View SourceShow Source...

LPad and RPad
Are a simpler version of the StrFill function (using spaces only).
View SourceShow Source...
GetPos, CountFields and GetField
These functions are particularly useful with retrieving a substring from a string using a specified delimiter. The GetPos function returns the position of the nth delimiter with a given string. The CountFields function counts the number of delimiters within a given string and adds one to the count which gives the number of fields delimited by the given delimiter character. The GetField function returns a sub-string from a given string using a specified character as a delimiter.
View SourceShow Source...

InitCap
This function will captialise the initial character of each word within a string.
View SourceShow Source...

GetUserName
This function allows the programmer to pick up the login name of the current user of the system (works with Windows 95/98/NT4 and W2K).
View SourceShow Source...

GetComputerName
This function retrieves the name of the local computer.
View SourceShow Source...

GetMachineInfo
This function retrieves the type of Operating System that the local machine is running. The results are returned in a record showing the platform, version, build and an amalgamation of the previous three as a description.
View SourceShow Source...

ExecuteFile
This routine gives the programmer a quick and easy way of running third-party applications from a Delphi app.
View SourceShow Source...

RealToStr
This function is similar to the standard "CurrToStr" function but allows the programmer to specify the amount of decimal places in the returning string.
View SourceShow Source...

ShellExec
This function is similar to the ExecuteFile function but allows you to wait for the called application to finish before carrying on with your application.
View SourceShow Source...
 

Web Site PortfolioWeb Site Portfolio


A beautiful hotel in the north of Scotland

A floating restaurant based in Stratford-upon-Avon

A Holiday Home Booking Web Site

Moving to Canada

The official GKI Karate web site in the UK.

The South Birmingham Goju Ryu Karate Clubs Dojos.

My Sensei's Web Site in Wokingham.

Senseis Andre & Daphne's Web Site in Camberley.