Clone wiki

OLTypes / Home


The OLTypes Delphi library enhances Boolean, Integer, Currency, Double, TDate, TDateTime and String types with some useful methods and ability to store Null values.

The library was tested with Delphi 2010, Delphi XE and Delphi 10.1. It will not work in Delphi 2005 and below.

###Licence### OLTypes library is distributed under the MIT License.


  • Download library and unpack it.
  • Add all units to your project or add path to source folder to your project's Search path (Menu Project->Options->Delphi Compiler->Search path->Browser for folder->Add->OK)
  • Add OLTypes to the uses section in your program

When you add source folder to Library path
(Menu Tools->Options->Environment Options->Delphi Options->Library->Library path [...]->Browser for folder->Add->OK)
then every new project will have OLTypes in its Browsing path.

I encourage you to look at the the OLTypesTest project. It is not only a test project for the library but also source of examples how to use it

###Three Quick Examples###


procedure OLIntegerTest();
  i: Integer;
  b: Boolean;
  s: string;
  SuperI: OLInteger; 
  b := SuperI.IsNull();               // default value is Null
  i := 5;
  SuperI := i;                        // you can assign regular Integer to it
  s := SuperI.ToString();             // like IntToStr but cleaner
  SuperI := SuperI + 4;               // this is fine
  SuperI := Null;                     // assign Null
  SuperI := SuperI.IfNull(6);         // when Null assign 6
  b := SuperI.IsEven();               // divisible by 2
  b := (SuperI >= 9);                 // compare against Integer
  SuperI.SetRandom(100);              // set random integer - Watch out, mutable! 
  SuperI := SuperI.Max(200).Min(400); // Method chain. Max returns OLInteger
  s := IntToStr(SuperI) + '.');       // Can replace Integer parameter (except var and const params)
  b := SuperI.IsPrime();              // Is it?
  i := SuperI;                        // assign back to regular Integer. (Will raise Exception when Null);


procedure OLStringTest();
  s: string;
  SuperS: OLString;
  s := 'This is a test';

  if SuperS.IsEmptyStr() then                   // Default value is empty string (!) not Null like in other OLTypes
    SuperS := s;                                // Assign a regular string
  SuperS[1] := 't';                             // Change a char in the string like in regular string
  SuperS := SuperS + ' !!! ';                   // Concatenate a string
  SuperS := Null;                               // Assign Null
  SuperS := SuperS.IfNull('New string');        // returns 'New string' when variable is Null
  SuperS.SaveToFile('c:\text.txt');             // Save to a file
  SuperS.LoadFromFile('c:\text.txt');           // Load a file
  SuperS.LineAdd('Second Line');                // Just like TStringList
  SuperS.Lines[1] := 'It is the 2. line.';      // but without the Create / Free hassle
  SuperS := SuperS.Compressed();                // Compress a text
  SuperS := SuperS.Decompressed();              // Decompress it back
  SuperS := SuperS.MidStr(11, 4);               // Get part from the middle
  SuperS := OLType('Aa;Bb;Cc;Dd').LowerCase();  // Cast with OLType function
  SuperS := SuperS.CSV[1];                      // Get the second field - 'bb' here
  SuperS.CSV[4] := 'ee';                        // Set value of the field: new field added here
  SuperS.CopyToClipboard();                     // You can also PasteFromClipboard
  if SuperS.Like('%cc_dd%') then                // Use SQL like patterns to test if OLString matches
    SuperS := 'Contains cc[some_char]dd!';

  s := SuperS;                                  // Assign it back to regular string variable


procedure OLDateTest();
  d: TDate;
  i: integer;
  b: Boolean;
  SuperD: OLDate;
  d := Date();

  if SuperD.IsNull() then             // Default value is Null
    SuperD := d;                      // Assign regular TDate value
  SuperD.Year := 2018;                // Change the year
  SuperD := SuperD.IncMonth(5);       // Add 5 months
  SuperD := '2017-05-12';             // You can use current format or ISO 8601;

  b := SuperD.InRange('2018-01-01', '2019-01-01');
  i := SuperD.EndOfAMonth(2018, 2).DaysInMonth();

  SuperD := 'epm';                    // The 'epm' is a SmartString interpreted as end of the prior month
  ShowMessage(SuperD.ToString());     // like DateToStr

  SuperD := Now();                    // assigning TDateTime will cut off the time part UNLIKE in TDate
  b := (SuperD = Date());             // so b is true

  d := SuperD;                        // Assign OLDate to regular TDate variable