StartprogrammingusingObjectPascal:Sets

From 흡혈양파의 번역工房
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Set

Set 형식은 하나의 변수에 여러가지 속성이나 특징을 지닐 수 있습니다. Set은 서수 값으로만 사용 합니다.

예를 들어, 프로그램에 운영체제 지원에 대해 정의하려 한다면, 다음처럼 할 수 있습니다.

1. 운영 체제를 나타내는 서수형을 정의합니다: TApplicationEnv

TApplicationEnv = (aeLinux, aeMac, aeWindows);

2. 프로그램을 TApplicationEnv의 Set으로 정의합니다.
예를 들면

FireFox: set of TApplicationEnv;

3. 프로그램 Set 변수에 운영체제 값을 넣습니다.

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.

또한 정수

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

또는 문자와 같은 다른 서수형에 대한 Set 구문을 사용할 수 있습니다.

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