Jump to content

Timp rămas până la Black Week

Pentru detalii complete despre promoție click aici

Black Week a început!

Pentru detalii complete despre promoție click aici

[PASCAL] Sets


CouldnoT
 Share

Recommended Posts

Sets

 

Set types can hold multiple properties or characteristics in one variable. Sets are used only with ordinal values. For example, if we need to define the operating system's support for applications, we can do it as in the following:

 

1. Define ordinal type that represents operating systems: TApplicationEnv:

 

  TApplicationEnv = (aeLinux, aeMac, aeWindows);

 

2. Define the application as set of TApplicationEnv: for example:

 

  FireFox: set of TApplicationEnv;

 

3. Put operating system values in the application set variable:

 

 FireFox:= [aeLinux, aeWindows];
program Sets;
{$mode objfpc}{$H+}
uses
 {$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
 {$ENDIF}{$ENDIF}
 Classes
 { you can add units after this };
type
 TApplicationEnv = (aeLinux, aeMac, aeWindows);
var
 FireFox: set of TApplicationEnv;
 SuperTux: set of TApplicationEnv;
 Delphi: set of TApplicationEnv;
 Lazarus: set of TApplicationEnv;
begin
 FireFox:= [aeLinux, aeWindows];
 SuperTux:= [aeLinux];
 Delphi:= [aeWindows];
 Lazarus:= [aeLinux, aeMac, aeWindows];
 if aeLinux in Lazarus then
 Writeln('There is a version for Lazarus under Linux')
 else
 Writeln('There is no version of Lazarus under linux');
 if aeLinux in SuperTux then
 Writeln('There is a version for SuperTux under Linux')
 else
 Writeln('There is no version of SuperTux under linux');
 if aeMac in SuperTux then
 Writeln('There is a version for SuperTux under Mac')
 else
 Writeln('There is no version of SuperTux under Mac');
 Readln;
end.

 

Also we can use set syntax for other ordinal types, like Integers:

 

if Month in [1, 3, 5, 7, 8, 10, 12] then
 Writeln('This month contains 31 days');

 

Or character:

 

if Char in ['a', 'A'] then
 Writeln('This letter is A');

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.