Difference between revisions of "TTICheckListBox"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "For editing set of enumerated types. type TMonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); TMonths = set of TMonth; TForm1 = class...")
 
(add syntax hilite blocks)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
For editing set of enumerated types.  
+
For editing set of enumerated types. Let's assume that we have following definitions.  
 
+
<syntaxhighlight lang="Pascal">
 
   type
 
   type
 
       TMonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
 
       TMonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
 
       TMonths = set of TMonth;
 
       TMonths = set of TMonth;
 +
      //
 
       TForm1 = class(TForm)
 
       TForm1 = class(TForm)
 
       private
 
       private
Line 10: Line 11:
 
         property Months: TMonths read FMonths write FMonths;
 
         property Months: TMonths read FMonths write FMonths;
 
       end;
 
       end;
 +
</syntaxhighlight>
  
 +
Properties of TTICheckListBox.Link can be assigned as following way.
  
You can use TTICheckListBox in following way.  
+
<syntaxhighlight lang="Pascal">
 +
      with TICheckListBox1.LInk do begin
 +
          TIObject:= Form1;
 +
          TIPropertyName := 'Months';
 +
      end;
 +
</syntaxhighlight>
  
 +
Assigning TTICheckListBox.Link.AliasValues will change displayed string of items. So, if defined in following way,
 +
 +
<syntaxhighlight lang="Pascal">
 
       with TICheckListBox1.LInk do begin
 
       with TICheckListBox1.LInk do begin
 +
          with AliasValues do begin
 +
            Clear;
 +
            Add('Jan=January');
 +
            Add('Feb=February');
 +
            Add('Mar=March');
 +
            Add('Apr=April');
 +
            Add('Nov=November');
 +
            Add('Dec=December');
 +
          end;
 
           TIObject:= Form1;
 
           TIObject:= Form1;
 
           TIPropertyName := 'Months';
 
           TIPropertyName := 'Months';
 
       end;
 
       end;
 +
</syntaxhighlight>
 +
 +
The checklist items will be displayed in following way and order:
 +
 +
    January
 +
    February
 +
    March
 +
    April
 +
    November
 +
    December
 +
    May
 +
    Jun
 +
    Jul
 +
    Aug
 +
    Sep
 +
    Oct
 +
   
 +
The "checked" months will be correctly stored in the FMonths field of Form1. That is, if you ckeck November, then
 +
<syntaxhighlight lang="Pascal">
 +
      Nov in FMonths
 +
</syntaxhighlight>
 +
 +
will return true.

Latest revision as of 18:02, 2 April 2022

For editing set of enumerated types. Let's assume that we have following definitions.

   type
      TMonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
      TMonths = set of TMonth;
      //
      TForm1 = class(TForm)
      private
         FMonths: TMonths;
      published
         property Months: TMonths read FMonths write FMonths;
      end;

Properties of TTICheckListBox.Link can be assigned as following way.

      with TICheckListBox1.LInk do begin
          TIObject:= Form1;
          TIPropertyName := 'Months';
      end;

Assigning TTICheckListBox.Link.AliasValues will change displayed string of items. So, if defined in following way,

      with TICheckListBox1.LInk do begin
          with AliasValues do begin
             Clear;
             Add('Jan=January');
             Add('Feb=February');
             Add('Mar=March');
             Add('Apr=April');
             Add('Nov=November');
             Add('Dec=December');
          end;
          TIObject:= Form1;
          TIPropertyName := 'Months';
      end;

The checklist items will be displayed in following way and order:

    January
    February
    March
    April
    November
    December 
    May
    Jun
    Jul
    Aug
    Sep
    Oct
    

The "checked" months will be correctly stored in the FMonths field of Form1. That is, if you ckeck November, then

      Nov in FMonths

will return true.