Friday, March 20, 2020
Understanding Delphi SET Type - Expert Guide
Understanding Delphi SET Type - Expert Guide One of the Delphi language features not found in other modern languages is the notion of sets. Delphis set type is a collection of values of the same ordinal type. A set is defined using the set of keyword: Set types are usually defined with subranges. In the above example, the TMagicNumber is a custom subrange type allowing variables of the TMagicNumber type to receive values from 1 to 34. Simply put, a subrange type represents a subset of the values in another ordinal type. Possible values of the set type are all the subsets of the base type, including the empty set. A limitation on sets is that they can hold up to 255 elements. In the above example, the TMagicSet set type is a set of TMagicNumber elements - integer numbers from 1 to 34. The declaration TMagicSet set of TMagicNumber is equal to the following declaration: TMagicSet set of 1..34. Set Type Variables In the above example, the variables emptyMagicSet, oneMagicSet and anotherMagicSet are sets of TMagicNumber. To assign a value to a set type variable, use the square brackets and list all the elements of the set. As in: Note 1: every set type variable can hold the empty set, denoted by []. Note 2: the order of the elements in a set has no meaning, nor is it meaningful for an element (value) to be included twice in a set. The IN Keyword To test if an element is included in the set (variable) use the IN keyword: Set Operators The same way you can sum two numbers, you can have a set that is the sum of two sets. With sets your event has more operators: returns the union of two sets.- returns the difference of two sets.* returns the intersection of two sets. return true if two sets are equal - have the same element. returns true if the first set is a subset of the second set. returns true if the first set is a superset of the second set. returns true if two sets are non-identical.IN returns true if an element is included in the set. Heres an example: Will the ShowMessage procedure be executed? If so, what will be displayed? Heres the implementation of the DisplayElements function: Hint: yes. Displayed: 18 | 24 |. Integers, Characters, Booleans Of course, when creating set types you are not restricted to integer values. Delphi ordinal types include character and boolean values. To prevent users to type alpha keys, add this line in the OnKeyPress of an edit control: Sets with Enumerations A commonly used scenario in Delphi code is to mix both enumerated types and set types. Heres an example: Question: will the message be displayed? Answer: no :( Sets in Delphi Control Properties When you need to apply bold to the font used in TEdit controls, you either use the Object Inspector or the following code: The Fonts Style property is a set type property! Heres how it is defined: So, an enumerated type TFontStyle is used as the base type for the set type TFontStyles. The Style property of the TFont class is of type TFontStyles - therefore a set type property. Another example includes the result of the MessageDlg function. A MessageDlg function is used to bring up a message box and obtain the users response. One of the parameters of the function is the Buttons parameter of type TMsgDlgButtons. TMsgDlgButtons is defined as a set of (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp). If you display a message to the user containing Yes, OK and Cancel buttons and you want to execute some code if either the Yes or Ok buttons were clicked you can use the next code: Final word: sets are great. Sets might appear confusing to a Delphi beginner, but as soon as you start using set type variables you will find out they provide much more then it sounded in the beginning.
Wednesday, March 4, 2020
Impervious and Impenetrable
Impervious and Impenetrable Impervious and Impenetrable Impervious and Impenetrable By Maeve Maddox The synonyms impervious and impenetrable have similar meanings, but, depending on context, one is preferable to the other. The words are used both literally and figuratively. Here are their literal meanings: impervious: Through which there is no way; not affording passage (to); not to be passed through or penetrated; impenetrable, impermeable, impassable. impenetrable: That cannot be penetrated, pierced, or entered; impossible to get into or through. Both words are negatives. Impervious is formed from the negative prefix im- and the adjective pervious. Impenetrable combines the same prefix, im-, with the adjective penetrable, which in turn comes from the verb penetrate. pervious: adjective. Allowing the passage of water, air, etc., through its substance; permeable. Freq. with to. penetrate: transitive verb. To get into or through, gain entrance or access to, especially with force, effort, or difficulty; to pierce. For example, using the words literally, one might say that cheesecloth is pervious to air and water, while a raincoat is impervious to water. The words are used frequently in a figurative sense. If something is impervious, things wash over it without entering. It remains sealed from outside influences. Something impenetrable is not only impervious, it resists efforts to pierce it, either literally, with a pointed object, or figuratively, with the mind. Compare the uses of both words in the following quotations from the web: Such a standard was originally developed to ensure that governments and other organizations could maintain electronic archives that would be relatively impervious to changes in technology. Recruits become fanatics on the subject, impervious to argument, quick to cut themselves off from doubters. After listening to the debate people made up their minds and were fairly impervious to new information. Let your plans be dark and impenetrable as night, and when you move, fall like a thunderbolt. Sun Tzu, The Art of War. After 9,000 emendations to James Joyces notoriously impenetrable novel, a smoother new edition is promised. The Guardian Want to improve your English in five minutes a day? Get a subscription and start receiving our writing tips and exercises daily! Keep learning! Browse the Vocabulary category, check our popular posts, or choose a related post below:Passed vs PastLatin Plural EndingsOne "L" or Two?
Subscribe to:
Posts (Atom)