Delphi RTL and Language Wisdom

It’s Tuesday and following up my VCL list from yesterday, here my list for the RTL and Object Pascal language:

  • Learn to create your own TList descendants
  • Learn to write your own TCollection/TCollectionItem descendants
  • Use Format
  • Learn TThread then, understand TThread.Synchronize
  • Use TFileStream, TStringStream, TMemoryStream
  • Learn how to use the classes in SyncObjs.pas
  • Learn to call a function from a dynamically loaded DLL
  • Use exceptions
  • Learn when to use stdcall
  • Learn to use open array parameters
  • Use the *utils.pas units, DateUtils, StrUtils, MaskUtils, ConvUtils, VarUtils etc.
  • Learn the Math unit
  • Use SafeMM
  • Learn which exceptions the RTL throws
  • Use try…finally
  • Read the comments in SysUtils.pas
  • Call FindClose after calling FindFirst
  • Learn how to load packages dynamically
  • Use FindCmdLineSwitch
  • Just because it’s not in Windows.pas doesn’t mean it can’t be called from Delphi
  • Learn function inlining
  • Be careful using “with”
  • Learn to use interfaces
  • Use dynamic arrays
  • Read the Language Reference manual

What am I missing?

3 thoughts on “Delphi RTL and Language Wisdom

  1. First: always use FreeAndNil(X) instead of X.Free.
    Second, the biggest single time-saver for me is my own TMonitoredObject class. It inherits from TObject, but adds a sequential ID number for each instance. If I $DEFINE DEBUG, the constructor and destructor each write a log entry indicating that they’ve been called, along with the actual class name and ID number. At the end of a program run, the unit that defines TMonitoredObject gives me a list of any objects that haven’t been freed. It also tracks double-freeing, although that’s less of an issue if you use FreeAndNil. Just insure you always use type TFoo = class(TMonitoredObject) instead of TFoo = class, and you’re set. In one fell swoop, it makes memory leaks virtually impossible. I can stick a copy up somewhere if you want to see it, but it’s pretty easy to produce just from that description.

  2. Sebastian,
    Ben Taylor did work on SafeMM though I can’t find much about it on the web. I’ll dig up what I have about it and get it posted. We use it here to help strictly with memory leak detection.

Comments are closed.