Delphi 컬렉션

10843 단어 Delphi
컬렉션
//  
type
  Uppercase = 'A'..'Z';
  Letters = set of Uppercase;  //      

  TBorderIcon = (biSystemMenu, biMinimize, biMaximize, biHelp);
  TBorderIcons = set of TBorderIcon;  //      

  
// type Uppercase = 'A'..'Z'; Letters = set of Uppercase; // var L1, L2, L3: Letters; begin L1 := ['A', 'B', 'C']; L2 := ['K']; L3 := []; if 'A' in L1 then ShowMessage('true'); //true if L2=['K'] then ShowMessage('true'); //true if L3=[] then ShowMessage('true'); //true end;
// type TSet = set of (A,B,C); var set1: TSet; begin set1 := [A,B]; if A in set1 then ShowMessage(' set1 A'); end;
// type TSet = set of (A,B,C); var set1: TSet; begin set1 := [A]; set1 := set1 + [B]; // Include(set1,B); // set1 := set1 - [B]; // Exclude(set1,B); // end;
// type TCharSet = set of char; var character: 'a'..'z'; charSet: TCharSet; word: string; begin charSet := []; for character in [Low(character) .. High(character)] do begin if character in ['d', 'e', 'l', 'p', 'h', 'i'] then begin Include(charSet, character); end; end; for character in charSet do begin word := word + character; end; ShowMessage(word); //dehilp end;
컬렉션 요소 개수 가져오기
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  set1: set of Char; {          }
  c: Char;           {           }
  num: Integer;      {    }
begin
  set1 := ['a'..'z', 'A'..'Z', '0'..'9']; {     }
  
  num := 0;
  for c in set1 do Inc(num); {       set1,   num   }   

  ShowMessage(IntToStr(num)); {62}
end;

end.

좋은 웹페이지 즐겨찾기