Delphi Fixes
A Delphi unit aiming to reduce frustration from Delphi's incompetency and complexity
ToStr(), ToInt(), ToFloat():
- These custom functions are designed to help speed up typecasting
- Any type of variable can be inputted into these functions and (hopefully) the correct type will be outputted
RemoveCharacter() & RemoveManyCharacters():
- Procedures to remove characters
- RemoveCharacter() inputs a single character and the string to be processed, aswell as a boolean for case sensitive
- RemoveManyCharacters() is the same as RemoveCharacter() except a string of the characters to remove is inputted rather than a character
LocalFilePath():
- A function to output the complete file path for the file inputted (assuming the file is in the same folder or in a sub folder found in the projects folder)
eg.
Your project is stored in 'C:\Delphi Projects':
LocalFilePath('image.png') will return 'C:\Delphi Projects\image.png'
LocalFilePath('Images\image.png') will return 'C:\Delphi Projects\Images\image.png'
ConnectDatabase():
- A procedure to connect a ADOConnection to a .mdb file at the specified path (if only part of the path is given it assumes it is in the same directory as the project or in a subfolder in that directory)
ConnectTable():
- A procedure to connect a ADOTable to the specified ADOConnection
EditRecord() & InsertRecord():
- Two very similar procedures to edit/insert records in the specified table
- The input of the fields are specified using an array
- Inputs for ALL the fields should be given in their original data type
- To avoid errors when processing, if a field is an autonumber no changes will be made
eg.
InsertRecord(tblUsers, ['', 'Bhavan', 'P@$$w0rd', '3 October 2007']) - The fields are UserID | Username | Password | DateOfBirth
Will output:
UserID | Username | Password | DateOfBirth
1 | Bhavan | P@$$w0rd | 03/10/2007
DeleteRecord():
- A procedure based on Delphi's TADOTable.Delete procedure
- Also checks if the specified table is not empty to avoid errors
CloseTables() & OpenTables():
- Procedures that close all tables inputted through an array
Notable things:
- If a float is inputted into ToInt(), it will be correctly rounded off (Unlike the default Round() function)
- ToFloat() will work with both commas and decimals and (hopefully) won't cause any errors (The other weird Windows formatting for decimals probably won't work though)
- For RemoveManyCharacters() the list of characters must be inputted as a string
- DeleteRecord(), InsertRecord() and EditRecord() check if the table is already opened, if not the table will be opened at the begining and closed at the end
Enjoy!