2

As the title says, I would like to know what is the meaning of the pipe (or tube) "|" in a Delphi code. See that screenshot :

enter image description here

I know the meaning of "*" which is a wild card for one or more characters, but I can't find what means "|".

Thanks

AymericB
  • 162
  • 1
  • 4
  • 16
  • 1
    It's a `|` inside a string literal. Therefore it's not a syntax element. It's a separator. In other places in Delphi you'll find `;` used as a path separator (such as in the library path in the IDE settings), and in many cases, when you want multiple values, in components you'll see the more typical `Items:TStrings` property where each item is a separate item in a list. – Warren P Jan 26 '16 at 14:11
  • I'm curious what "regles de chauffage" means? Rules for heating? Rules for Driving? – Warren P Jan 26 '16 at 14:13
  • Heating rules yes ;) The program deals with industrial furnaces. By the way, thank you for your precision – AymericB Jan 26 '16 at 15:30

5 Answers5

9

This is a question that can be answered by reading the documentation. It can be found here:

Vcl.Dialogs.TOpenDialog.Filter

To create file masks in program code, assign a value to the Filter property that consists of a description and a mask separated by a vertical bar (pipe) character. Do not include spaces around the vertical bar. For example,

OpenDialog1.Filter := 'Text files (*.txt)|*.TXT';

Multiple filters should be separated by vertical bars. For example,

OpenDialog1.Filter := 'Text files (*.txt)|*.TXT|Pascal files (*.pas)|*.PAS';

To include multiple masks in a single filter, separate the masks with semicolons. This works both in the Object Inspector and in program code. For example,

OpenDialog1.Filter := 'Pascal files|*.PAS;*.DPK;*.DPR';

You might like to absorb the hints found here (How can I search for Delphi documentation?) in order to help you in the future.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you for your links, I should have sought directly in the documentation of the TOpenDialog. I thought it was something more general about Delphi, not specially about the TOpenDialog component. – AymericB Jan 26 '16 at 11:42
  • 2
    From the language perspective it's just a character in a string, nothing more esoteric than that. – David Heffernan Jan 26 '16 at 11:45
  • 1
    @AymericB Actually this is not about Delphi at all. It is actually requirement from Windows API used to display many common dialog boxes (Open Dialog, Open Picture Dialog, Save Dialog, Save Picture Dialog, etc). You see most dialogs in Delphi are just wrapers for common dialogs exposed through Windows API. And it is the requirement of the windows API to include `|` character in the string defining the filter https://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filter(v=vs.110).aspx – SilverWarior Jan 26 '16 at 17:52
  • 1
    @Silver Nope. That's a .net class you link to, using the same conventions as Delphi does. I'll bet they originated in VB. – David Heffernan Jan 26 '16 at 17:57
  • 1
    @DavidHeffernan I agree with your. In my haste I have provided link to wrong documentation. I'm not very good at searching the MSDN documentation. So if you can find documentation feel free to extend your answer with this information. I just know that use of `|` character is requirement for common file dialog boxes ever since Windows 2000 if not even older. – SilverWarior Jan 26 '16 at 18:18
  • 1
    @Silver That's not the case. Look at the docs for GetOpenFileName. – David Heffernan Jan 26 '16 at 18:21
4

In Delphi, the | character is often used as separator in certain string properties to differentiate between:

  • The description and the mask of a file filter, as used in TOpenDialog.Filter.
  • The short part, the long part and the image index of a hint text, as used in all Hint properties.
NGLN
  • 43,011
  • 8
  • 105
  • 200
3

The pipe separates the filter expression (on the right) from the caption the user will see (on the left). If you want to apply more than one filter, just append it, also separated by pipes.

Franz Wimmer
  • 1,477
  • 3
  • 20
  • 38
1

For TOpenDialog this is just a syntax to specify in one line of Filter both:

  • friendly type name (here: Regles de chaurfage)
  • file extension related to the type (here .fuz)

This is not language operator. This is just some kind of convention TOpenDialog is using.

Kuba Wyrostek
  • 6,163
  • 1
  • 22
  • 40
1

Multiple filters should be separated by vertical bars.

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Dialogs_TOpenDialog_Filter.html

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • OK, so in fact "Règle de chauffage" is just the description ! That description is separated of the mask with "|". So the filter is just *.fuz finally. – AymericB Jan 26 '16 at 10:41
  • 1
    Exactly. Also the pipe separates multiple file types. The link I have given clears it out. – Charlie Jan 26 '16 at 11:03