Delphi Tips Page
These Tips are contributed by you (our online community members). They are organized by our knowledge base topics. Specifically, by the Delphi sub-topics.
|
5 Pascal and Delphi Coding Tips
Group: Pascal and Delphi Coding
Topic: Tool Basics
1. Insert GUID Into Source Code
To insert a GUID into code using the Delphi Editor, use Control + Shift + G. ['{BB45987C-0552-415F-A439-636A87E9F4E2}']
However, if you are using either the Visual Studio or Visual Basic key mapping emulation, use Control + Alt + G.
|
Topic: Language Basics
2. One Recommended way of writing IF/End IF statements
Format the IF/Endif for easy reading. I have found this to be easy to read and follow: if ( (something = somethingelse) and (x = y) and (z = a) ) then begin .. end;
To indent the structure and line up the parenthesis makes it, I feel, much easier to read.
|
Topic: Language Details
3. Associative Arrays in Delphi/Object Pascal
Although Object Pascal doesn't have a native associative array, many developers just use a TStringList. Others have implemented a true associative array in Object Pascal. Search the Internet for TStringHash and THashedStringList classes for examples.
|
Topic: Using Data
4. Quoting Your String (QuotedStr and AnsiQuotedStr)
When you need to put quotes, single or double, or even another character, around a string there are two methods to lend a hand: QuotedStr and AnsiQuotedStr. QuotedStr will put single (') quotes around your string or variable. The other function you can call is AnsiQuotedStr which adds double quotes.
|
5. TStringList - Maximizing Performance
Before adding many new entries to a TStringList, set its Sorted property to false. Add all your entries. Finally, set the Sorted property back to True (if desired).
Sorting is expensive, in terms of macnine cycles. By leaving the Sorted property set to True, you force the TStingList to re-sort itself after each entry. This can significantly slow things down.
This applies to TStrings, as well, and all components that have a TStrings property, like TListBox, etc.
|
|
|