Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fill a Delphi set?

Tags:

set

delphi

If I have a type defined as a set of an enumerated type, it's easy to create an empty set with [], but how do I create a full set?

EDIT: Yeah, the obvious solution is to use a for loop. That's also a really bad solution if there's another way. Does anyone know of a way that'll work in constant time?

like image 687
Mason Wheeler Avatar asked Oct 31 '08 22:10

Mason Wheeler


People also ask

What is a set type in Delphi?

Delphi's 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.

How to print in Delphi?

Delphi provides modern full text and graphics printing facility. We can print texts, images and shapes in different formats by using several Delphi classes and members. We can also access printers installed on system and can change their properties Print and printer setup dialog in Delphi.

How to prevent users to type alpha keys in Delphi code?

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: A commonly used scenario in Delphi code is to mix both enumerated types and set types. Question: will the message be displayed?

What is an open array in Delphi?

Such an array is referred to as an Open array. Delphi passes the length as a hidden parameter to the subroutine. An open array may also be defined with const value type. This is called a Variant open array - it is mostly used to allow a variable number of argument value to be passed to a subroutine.


1 Answers

Low() and High() are "compiler magic" functions that can be evaluated at compile time. This allows their use in constant declarations like the following:

var
  MySet : TBorderIcons;
  MySet2 : TBorderIcons;
const
  AllIcons : TBorderIcons = [Low(TBorderIcon)..High(TBorderIcon)];
begin
  MySet := [Low(TBorderIcon)..High(TBorderIcon)];
  MySet2 := AllIcons;
end;
like image 75
Gerry Coll Avatar answered Sep 24 '22 07:09

Gerry Coll