Ignore:
Timestamp:
Mar 29, 2019, 12:58:09 PM (6 years ago)
Author:
chronos
Message:
  • Added: New enumeration field type in generic TItem classes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormItem.pas

    r291 r296  
    8989  Fields: TItemFields;
    9090  I: Integer;
     91  J: Integer;
    9192  Control: TControl;
    9293begin
     
    99100    else if DataType = dtColor then TColorBox(Control).Selected := Item.GetValueColor(Index)
    100101    else if DataType = dtBoolean then TCheckBox(Control).Checked := Item.GetValueBoolean(Index)
    101     else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType)));
     102    else if DataType = dtEnumeration then begin
     103      TComboBox(Control).Items.BeginUpdate;
     104      try
     105        TComboBox(Control).Items.Clear;
     106        for J := 0 to EnumStates.Count - 1 do
     107          TComboBox(Control).Items.Add(EnumStates[J]);
     108        TComboBox(Control).ItemIndex := Integer(Item.GetValueEnumeration(Index));
     109      finally
     110        TComboBox(Control).Items.EndUpdate;
     111      end;
     112    end
     113    else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    102114  end;
    103115  Fields.Free;
     
    118130    else if DataType = dtColor then Item.SetValueColor(Index, TColorBox(Control).Selected)
    119131    else if DataType = dtBoolean then Item.SetValueBoolean(Index, TCheckBox(Control).Checked)
    120     else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType)));
     132    else if DataType = dtEnumeration then Item.SetValueEnumeration(Index, TUndefinedEnum(TComboBox(Control).ItemIndex))
     133    else raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    121134  end;
    122135  Fields.Free;
     
    145158      NewControl := TSpinEdit.Create(nil);
    146159      NewControl.Width := 100;
     160      TSpinEdit(NewControl).MaxValue := High(Integer);
    147161    end else
    148162    if DataType = dtString then begin
     
    154168      NewControl.Width := 200;
    155169    end else
     170    if DataType = dtEnumeration then begin
     171      NewControl := TComboBox.Create(nil);
     172      NewControl.Width := 200;
     173      TComboBox(NewControl).Style := csDropDownList;
     174    end else
    156175    if DataType = dtBoolean then begin
    157176      NewControl := TCheckBox.Create(nil);
    158     end else raise Exception.Create('Unsupported type ' + IntToStr(Integer(DataType)));
     177    end else
     178      raise Exception.Create(Format(SUnsupportedDataType, [DataTypeStr[DataType]]));
    159179    NewControl.Left := 150;
    160180    NewControl.Top := Y;
Note: See TracChangeset for help on using the changeset viewer.