Case/fi

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) русский (ru)

Case aloittaa case-lauseen. Case-lauseessa verrataan muuttujan arvoa esitettyihin vakiona pysyviin arvoihin. Näitä vakiona pysyviä arvoja voi olla yksittäinen vakio, tietty vakioalue tai pilkulla erotettu joukko vakioita. Tietyn valinnan jälkeen suoretettavat lauseen on erotettu kaksoispisteellä.

Case-lause sisältää varatut sanat Of ja End sekä joskus myös Else.


 case place of
   1: ShowMessage('Kultamitali');
   2: ShowMessage('Hopeamitali');
   3: ShowMessage('Pronssimitali'); 
   else ShowMessage('Parempi onni ensi kerralla'); 
 end;

WhatIsChar

 function WhatIsChar( c:char ):string;
 var
   s : string;
 begin
   s := '';
   case c of
     '0' .. '9' : s := 'Numero (0-9)';
     'a' .. 'z' : s := 'Pieni kirjain (a-z)';
     'A' .. 'Z' : s := 'Iso kirjain (A-Z)';
     '+' , '-'  : s := 'Etumerkki (+ or -)';
   end;
   result := s;
 end;

Case of merkkijonoissa

Case of toimii myös merkkijonoissa. Pascal -kieli mahdollistaa "Case of" käytön string:llä.

const
  ISO_3166_1_ALPHA_3_ANDORRA  = 'AND';
  ISO_3166_1_ALPHA_3_AUSTRALIA = 'AUS';
  ISO_3166_1_ALPHA_3_AUSTRIA = 'AUT';
  ISO_3166_1_ALPHA_3_BELGIUM = 'BEL';
  ISO_3166_1_ALPHA_3_BRAZIL = 'BRA';
  ISO_3166_1_ALPHA_3_CANADA = 'CAN';
  ISO_3166_1_ALPHA_3_CHINA = 'CHN';
  ISO_3166_1_ALPHA_3_CZECH_REPUBLIC = 'CZE';
  ISO_3166_1_ALPHA_3_CYPRUS = 'CYP';
  ISO_3166_1_ALPHA_3_GERMANY = 'DEU';
  ISO_3166_1_ALPHA_3_DENMARK = 'DNK';
  ISO_3166_1_ALPHA_3_SPAIN = 'ESP';
  ISO_3166_1_ALPHA_3_ESTONIA = 'EST';
  ISO_3166_1_ALPHA_3_FINLAND = 'FIN';
  ISO_3166_1_ALPHA_3_FRANCE = 'FRA';
  ISO_3166_1_ALPHA_3_GREECE = 'GRC';
  ISO_3166_1_ALPHA_3_INDIA = 'IND';
  ISO_3166_1_ALPHA_3_IRELAND = 'IRL';
  ISO_3166_1_ALPHA_3_ITALY = 'ITA';
  ISO_3166_1_ALPHA_3_JAPAN = 'JPN';
  ISO_3166_1_ALPHA_3_LITHUANIA = 'LTU';
  ISO_3166_1_ALPHA_3_LATVIA = 'LVA';
  ISO_3166_1_ALPHA_3_LUXEMBOURG = 'LUX';
  ISO_3166_1_ALPHA_3_MALTA = 'MLT';
  ISO_3166_1_ALPHA_3_MEXICO = 'MEX';
  ISO_3166_1_ALPHA_3_MONACO = 'MCO';
  ISO_3166_1_ALPHA_3_MONTENEGRO = 'MNE';
  ISO_3166_1_ALPHA_3_NAURU = 'NRU';
  ISO_3166_1_ALPHA_3_NETHERLANDS = 'NLD';
  ISO_3166_1_ALPHA_3_NORWAY = 'NOR';
  ISO_3166_1_ALPHA_3_POLAND = 'POL';
  ISO_3166_1_ALPHA_3_PORTUGAL = 'PRT';
  ISO_3166_1_ALPHA_3_REPUBLIC_OF_KOREA = 'KOR';
  ISO_3166_1_ALPHA_3_RUSSIAN_FEDERATION = 'RUS';
  ISO_3166_1_ALPHA_3_SAN_MARINO = 'SMR';
  ISO_3166_1_ALPHA_3_SLOVAKIA = 'SVK';
  ISO_3166_1_ALPHA_3_SLOVENIA = 'SVN';
  ISO_3166_1_ALPHA_3_SWEDEN = 'SWE' ;
  ISO_3166_1_ALPHA_3_SWITZERLAND = 'CHE';
  ISO_3166_1_ALPHA_3_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND = 'GBR';
  ISO_3166_1_ALPHA_3_UNITED_STATES_OF_AMERICA = 'USA';


  ISO_4217_EURO = 'EUR';
  ISO_4217_AUSTRALIAN_DOLLAR = 'AUD';
  ISO_4217_BRAZILIAN_REAL = 'BRL';
  ISO_4217_CANADIAN_DOLLAR = 'CAD';
  ISO_4217_CHINESE_YUAN = 'CNY';
  ISO_4217_CZECH_KORUNA = 'CZK' ;
  ISO_4217_DANISH_KRONE = 'DKK' ;
  ISO_4217_INDIAN_RUPEE = 'INR';
  ISO_4217_POUND_STERLING = 'GBP' ;
  ISO_4217_JAPANESE_YEN  = 'JPY';
  ISO_4217_MEXICAN_PESO = 'MXN';
  ISO_4217_NORWEGIAN_KRONE = 'NOK' ;
  ISO_4217_POLISH_ZLOTY = 'PLN' ;
  ISO_4217_RUSSIAN_RUBLE = 'RUB' ;
  ISO_4217_SOUTH_KOREAN_WON = 'KRW';
  ISO_4217_SWEDISH_KRONA = 'SEK' ;
  ISO_4217_SWISS_FRANC = 'CHF' ;
  ISO_4217_UNITED_STATES_DOLLAR = 'USD' ;

function ISO_4217_currency_name ( ISO_3166_1_alpha_3_code: string): string;
begin
  Case ISO_3166_1_alpha_3_code  of
    // Euroalue
    ISO_3166_1_ALPHA_3_ANDORRA, ISO_3166_1_ALPHA_3_AUSTRIA,
    ISO_3166_1_ALPHA_3_BELGIUM,ISO_3166_1_ALPHA_3_CYPRUS,
    ISO_3166_1_ALPHA_3_GERMANY, ISO_3166_1_ALPHA_3_SPAIN,
    ISO_3166_1_ALPHA_3_ESTONIA, ISO_3166_1_ALPHA_3_FINLAND,
    ISO_3166_1_ALPHA_3_FRANCE, ISO_3166_1_ALPHA_3_GREECE,
    ISO_3166_1_ALPHA_3_IRELAND, ISO_3166_1_ALPHA_3_ITALY,
    ISO_3166_1_ALPHA_3_LITHUANIA, ISO_3166_1_ALPHA_3_LATVIA,
    ISO_3166_1_ALPHA_3_LUXEMBOURG, ISO_3166_1_ALPHA_3_MONACO,
    ISO_3166_1_ALPHA_3_MALTA, ISO_3166_1_ALPHA_3_MONTENEGRO,
    ISO_3166_1_ALPHA_3_NETHERLANDS, ISO_3166_1_ALPHA_3_PORTUGAL,
    ISO_3166_1_ALPHA_3_SAN_MARINO, ISO_3166_1_ALPHA_3_SLOVAKIA,
    ISO_3166_1_ALPHA_3_SLOVENIA : result := ISO_4217_EURO ;

    ISO_3166_1_ALPHA_3_AUSTRALIA, ISO_3166_1_ALPHA_3_NAURU :
          result := ISO_4217_AUSTRALIAN_DOLLAR;
    ISO_3166_1_ALPHA_3_BRAZIL : result := ISO_4217_BRAZILIAN_REAL;
    ISO_3166_1_ALPHA_3_CANADA : result := ISO_4217_CANADIAN_DOLLAR;
    ISO_3166_1_ALPHA_3_CHINA : result := ISO_4217_CHINESE_YUAN;
    ISO_3166_1_ALPHA_3_CZECH_REPUBLIC : result := ISO_4217_CZECH_KORUNA ;
    ISO_3166_1_ALPHA_3_DENMARK : result := ISO_4217_DANISH_KRONE ;
    ISO_3166_1_ALPHA_3_INDIA : result := ISO_4217_INDIAN_RUPEE;
    ISO_3166_1_ALPHA_3_JAPAN : result := ISO_4217_JAPANESE_YEN;
    ISO_3166_1_ALPHA_3_MEXICO : result := ISO_4217_MEXICAN_PESO;
    ISO_3166_1_ALPHA_3_NORWAY : result := ISO_4217_NORWEGIAN_KRONE ;
    ISO_3166_1_ALPHA_3_POLAND : result := ISO_4217_POLISH_ZLOTY ;
    ISO_3166_1_ALPHA_3_REPUBLIC_OF_KOREA : result := ISO_4217_SOUTH_KOREAN_WON ;
    ISO_3166_1_ALPHA_3_RUSSIAN_FEDERATION : result := ISO_4217_RUSSIAN_RUBLE ;
    ISO_3166_1_ALPHA_3_SWEDEN : result := ISO_4217_SWEDISH_KRONA ;
    ISO_3166_1_ALPHA_3_SWITZERLAND : result := ISO_4217_SWISS_FRANC ;
    ISO_3166_1_ALPHA_3_UNITED_KINGDOM_OF_GREAT_BRITAIN_AND_NORTHERN_IRELAND :
          result := ISO_4217_POUND_STERLING ;
    ISO_3166_1_ALPHA_3_UNITED_STATES_OF_AMERICA :
          result := ISO_4217_UNITED_STATES_DOLLAR ;
  end;
end;

Vaihteleva tietue

Case-sanaa käytetään myös vaihtelevassa tietueessa.

  type
      
   ScaleKelvin = 223 .. 323;
   ScaleCelsius = -50 .. 50;
    
   TemperatureScale   =  ( celcius, kelvin ) ;
   Temperature   =   record
    case  scale   :   TemperatureScale   of
     celcius : (celcius_value : ScaleCelsius);
     kelvin : (kelvin_value : ScaleKelvin);
   end;

Lisätietoja