CouldnoT Posted November 30, 2020 Share Posted November 30, 2020 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 More sharing options...
Recommended Posts