Thursday, February 15, 2018

Cool features and functions in Delphi

 

List of IDE features that are cool (when they work)

  • Search backwards - Ctrl+F to do a search in your code. F3 to go to the next position Shift+F3 to go to previous position.
  • Move/Relocate/Rename project's files directly from Project Manager
  • Navigate to recently modified code - Ctrl+Shift+F7 and Ctrl+Shift+F8
  • Search for usage - Right click a variable and invoke 'search for usage'. A panel will list all places in current project where that variable is used. In my cases this will make the IDE to freeze. 
  • UML diagrams (Live Diagrams) - simply doesn't work 
  • IDE insight (F6) - It could be useful but seems to list a lot of random items.
  • CodeSite - a logging system - I couldn't really find it useful
  • AQTime - Performance profiler + memory allocation debugger - I couldn't really find it useful


List of functions/units/classes that are cool (when they work)

  • SysUtils.GetHomePath - Returns c:\users\username\appdata\roaming.
  • IOUtils - Lots of new cool functions. Totally broken.
  • SplitString - Example of usage at the end of this document. Unfortunately, the function is VERY slow!
  • FindCmdLineSwitch - Example: System.SysUtils.FindCmdLineSwitch('-f', sFileName)
  • TThread.ProcessorCount;   { Specifies the number of CPU cores in the system }
  • TBinaryReader / TBinaryWriter - Nice but only half ass - Interesting but I recommend this library which is much faster: https://stackoverflow.com/questions/5639531
  • System.Diagnostics.TStopWatch - Can be used to precisely time your code.
  • $WeakLinkRTTI - Put these two directives in your DPR file (at the very top) to reduce exe size with 4%: {$WEAKLINKRTTI ON} {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
  • TStringBuilder - It was supposed to help you build strings. But it is horrible! Simply don't use it. It is painful slow.
  • PtInCircle & PtInRect - Tells you if a point is located in a circle. Could be handy one day.
  • TTimeSpan (System unit) is a data structure used for holding information about a period of time. The smallest unit of time is a tick which is 100 nanoseconds. The largest unit of time is a day.
CONST
  • SLineBreak - global constant that changes its value depending on target platform (Win/Linux/Mac)
  • Win32MajorVersion & Win32MinorVersion - To get current Windows version


List of VCL controls that are cool (when they work)

  • TJumpList - To list a custom file in a JumpList your program must be registered (in Windows registry) to be able to open that type of file. Another problem is that when the user clicks a 'recent file' in the JumpList, the message is not sent to your app directly. You need to intercept that message.









_________________________________

function CountWords(CONST s: string): Integer; { Might be faster than the one above }
VAR
   sArray: TStringDynArray;
begin
  sArray:= System.StrUtils.SplitString(s,  '.,? =<>*!-:;()/\'+cr+lf);
  Result:= Length(sArray);
end;