Delphi Constant Set

Delphi Constant Set Average ratng: 4,6/5 3293 reviews

You are familiar with this block:

Is there any way to declare Set Of STRING? or is there similar code that i can use instead? The important part of this block is If C In mySet Then ShowMessage('Exists'); I wanna use something like this about a set of string.
Thanks.

ArminArmin

Board index » delphi » How do I define a Global constant? Delphi Developer. Thu, 08 Feb 2001 03:00:00 GMT. And define global constants, variabels, and functions/procedures in this unit. Then add this units name in the Uses clause of all the units that are using the. > application using TfmMain.filepath its not set. I then move the.

4 Answers

Fabricio AraujoFabricio Araujo

Sets are implemented using bit arrays. So no, you cannot have a 'set of string'. Use a TStringList instead, ie:

Remy LebeauRemy Lebeau

The RTL System.StrUtils unit provides a very interesting method for this:

Use it like this:

Didier CabaléDidier Cabalé

It is shame, but Delphi still don't have even very basic data structures, like sets.Suggestion of 'Fabricio Araujo' is very limited in usage - you have to know all possible strings, so it is useless when you read them from somewhere. It is also impossible to have more then 256 items in such 'alsmost set of strings'. Remy Lebeau suggested to use TStringList for that purpose, but it is absolutely inefficient when you have big sets. In modern versions of Delphi it is possible to use TDictionary to keep unordered set of anything, including strings:

It is case sensitive. If you need case insensitive implementation, you can make all strings lowercased before put/look then in set (use AnsiLowerCase function for that).

Andrei GalatynAndrei Galatyn

Not the answer you're looking for? Browse other questions tagged delphidelphi-7 or ask your own question.

In Delphi, the versatile web-programming language, arrays allow a developer to refer to a series of variables by the same name and to use a number—an index—to tell them apart.

In most scenarios, you declare an array as a variable, which allows for array elements to be changed at run-time.

However, sometimes you need to declare a constant array—a read-only array. You cannot change the value of a constant or a read-only variable. Therefore, while declaring a constant array, you must also initialize it.

Example Declaration of Three Constant Arrays

This code example declares and initializes three constant arrays, named Days, CursorMode, and Items.

  • Days is a string array of six elements. Days[1] returns the Mon string.
  • CursorMode is an array of two elements, whereby declaration CursorMode[false] = crHourGlass and CursorMode = crSQLWait. 'cr*' constants can be used to change the current screen cursor.
  • Items defines an array of three TShopItem records.

Trying to assign a value for an item in a constant array raises the 'Left side cannot be assigned to' compile time error. For example, the following code does not successfully execute: