> ## Content Index
> Fetch the complete content index at: https://blogs.remobjects.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Delphi prism: With matching ....
- URL: https://blogs.remobjects.com/2009/01/13/delphi-prism-with-matching/
- Published: 2009-01-13T10:31:18.000Z
- Updated: 2018-08-22T06:17:48.000Z
- Author: Carlo Kok
- Tags: #Import 2026-08-17 20:17

a while ago we implemented a very useful feature called with matching. With matching is like with, but it does an <> nil check, and jumps over the whole block if it’s nil. This makes it possible to replace this:

| if lMyObj is MyType thenbeginvar lMyTypeRef :\= lMyObj as MyType; lMyTypeRef.Prop1:\=..lMyTypeRef.Prop2:\=..lMyTypeRef.Prop3:\=..lMyTypeRef.Prop4:\=..lMyTypeRef.Method1() lMyTypeRef.Method2()...end; |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

with:

| with matching lMyTypeRef :\= MyType(lMyObj)dobegin lMyTypeRef.Prop1:\=..lMyTypeRef.Prop2:\=..lMyTypeRef.Prop3:\=..lMyTypeRef.Prop4:\=..lMyTypeRef.Method1() lMyTypeRef.Method2()...end; |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

The matching keyword was originally introduced to allow a for each loop only process items that match a specific type like:

| for each matching el:stringin myarraylist dobegin MessageBox.Show(el);...end; |
| ----------------------------------------------------------------------------- |