"PosEx" Test

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

This is a program to define and test a substitute for the substring search function Posex that was  not available in versions before Delphi 7.    Here is Delphi's definition:

function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;

PosEx returns the index of SubStr in S, beginning the search at Offset. If Offset is 1 (default), PosEx is equivalent to Pos. PosEx returns 0 if SubStr is not found, if Offset is greater than the length of S, or if Offset is less than 1.

I coded my version to this definition so logically the code is similar.   I coded a version of Pos as a base for Posex and both are included here.   The program was written several years ago when a Delphi 5 user asked for one in order to recompile one of my the programs which uses Posex.  He recently wrote again because he had mislaid the original answer and, as a result, I decided to post the program here in Delphi techniques section. 

An even more interesting part of the project was implementing compile time conditional directives to include testing against the official Posex if  the program is compiled with Delphi  7 or later.   There is a predefined constant, CompilerVersion, which is compiled into each version of Delphi.  In can be tested in code to conditionally execute sections based on its value, however this doesn't work if the code to be executed references names not defined in the current Delphi version.  The solution is to use the conditional directives to include or exclude code in the source.  For example inserting Strutils into the Uses statement for Delphi 7 or later (to access PosEx), looks like this:

uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
{$IF declared(CompilerVersion) and (CompilerVersion>=15.0)}
    {$define TestPosEx}
  
 strutils,
{$IFEND}
StdCtrls, ShellAPI;

The variable TestPosEx is defined to use as a shortcut for testing in other code sections where the included testing for Delphi version of PosEx is to be included.  Like this:

{$IFDEF TestPosEx }

  ... insert Posex test code here

{$ENDIF}
 

A table associating Delphi external numbers with CompilerVersion  and RTLVersion (Run Time Library) numbers can be found at http://blog.blong.com/p/ancient-blog-posts.html.  Here's the pertinent table extracted from that interesting article:   

Product RTLVersion value CompilerVersion value
Kylix 1 14.00 not defined
Delphi 6.00 14.10 14.01
Delphi 6.01 14.11 14.01
Delphi 6.02 14.20 14.01
Delphi 6.02 with RTL Updates 14.31 14.01
C++Builder 6 14.20 14.01
Kylix 2 14.20 14.10
Kylix 3 14.50 14.50
Delphi 7.0x 15.00 15.00
Delphi for .NET Preview Edition not defined 16.00
Delphi 7.1 (Delphi 8 for .NET IDE Integration Pack) 15.00 16.00
Delphi 8.x for .NET 16.00 16.00
Delphi 2005 17.00 17.00
Delphi 2006 18.00 18.00
Delphi 2007 18.00 18.50
Delphi 2009 20.00 20.00
Delphi 2010 21.00 21.00
Delphi XE 22.00 22.00
Delphi XE2 23.00 23.00
Delphi XE3 24.00 24.00

 

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source 

Suggestions for Further Explorations

  ???
   

 

Original:  February 7, 2013

Modified:  May 12, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.