IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

July Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDelphi Knowledge Base  Print This    Tips Database All Groups  

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.

Contribute a Tip

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.

-
   Contact Us!
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


Go ahead!   Use Us! Call: 916-726-5675 


©1995-2017 Prestwood IT Solutions.   [Security & Privacy]