Ignore:
Timestamp:
Jan 23, 2015, 12:00:37 AM (10 years ago)
Author:
chronos
Message:
  • Modified: All data types have own table which is used to specify supported data types by database engines.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormField.pas

    r5 r8  
    6060
    6161uses
    62   UDataTypes;
     62  UDataTypes, UCore;
    6363
    6464{$R *.lfm}
     
    7171
    7272procedure TFormField.FormCreate(Sender: TObject);
    73 var
    74   I: TFieldType;
    7573begin
    76   ComboBoxType.Items.Clear;
    77   for I := Low(TFieldType) to High(TFieldType) do
    78     ComboBoxType.Items.Add(FieldTypeString[I]);
    7974end;
    8075
     
    8580
    8681procedure TFormField.Load(Field: TField);
     82var
     83  I: Integer;
     84  SelectedItem: TDataType;
    8785begin
     86  if ComboBoxType.ItemIndex <> -1 then
     87    SelectedItem := TDataType(ComboBoxType.Items.Objects[ComboBoxType.ItemIndex])
     88    else SelectedItem := nil;
     89
     90  with Field.Table.Database.Engine.DataTypes do begin
     91    while ComboBoxType.Items.Count > Count do
     92      ComboBoxType.Items.Delete(ComboBoxType.Items.Count - 1);
     93    while ComboBoxType.Items.Count < Count do
     94      ComboBoxType.Items.Add('');
     95    for I := 0 to Count - 1 do begin
     96      ComboBoxType.Items.Strings[I] := TDataType(Items[I]).Name;
     97      ComboBoxType.Items.Objects[I] := Items[I];
     98    end;
     99    if Assigned(SelectedItem) then
     100      ComboBoxType.ItemIndex := ComboBoxType.Items.IndexOfObject(SelectedItem);
     101  end;
     102
    88103  EditName.Text := Field.Name;
    89104  EditTextAfter.Text := Field.TextAfter;
    90105  EditTextBefore.Text := Field.TextBefore;
    91   ComboBoxType.ItemIndex := Integer(Field.FieldType);
     106  ComboBoxType.ItemIndex := ComboBoxType.Items.IndexOfObject(Field.DataType);
    92107  ComboBoxTypeChange(Self);
    93   if Field.FieldType = ftString then
    94     EditStringDefault.Text := TFieldString(Field.TypeRelated).DefaultValue;
    95   if Field.FieldType = ftDateTime then begin
    96     DateEditMin.Date := TFieldDateTime(Field.TypeRelated).Min;
    97     DateEditMax.Date := TFieldDateTime(Field.TypeRelated).Max;
    98   end;
    99   if Field.FieldType = ftInteger then begin
    100     SpinEditMin.Value := TFieldInteger(Field.TypeRelated).Min;
    101     SpinEditMax.Value := TFieldInteger(Field.TypeRelated).Max;
    102   end;
    103   if Field.FieldType = ftFloat then begin
    104     FloatSpinEditMin.Value := TFieldFloat(Field.TypeRelated).Min;
    105     FloatSpinEditMax.Value := TFieldFloat(Field.TypeRelated).Max;
     108  case Field.DataType.FieldType of
     109    ftString: begin
     110      EditStringDefault.Text := TFieldString(Field.TypeRelated).DefaultValue;
     111    end;
     112    ftDateTime: begin
     113      DateEditMin.Date := TFieldDateTime(Field.TypeRelated).Min;
     114      DateEditMax.Date := TFieldDateTime(Field.TypeRelated).Max;
     115    end;
     116    ftInteger: begin
     117      SpinEditMin.Value := TFieldInteger(Field.TypeRelated).Min;
     118      SpinEditMax.Value := TFieldInteger(Field.TypeRelated).Max;
     119    end;
     120    ftFloat: begin
     121      FloatSpinEditMin.Value := TFieldFloat(Field.TypeRelated).Min;
     122      FloatSpinEditMax.Value := TFieldFloat(Field.TypeRelated).Max;
     123    end;
    106124  end;
    107125end;
     
    112130  Field.TextBefore := EditTextBefore.Text;
    113131  Field.TextAfter := EditTextAfter.Text;
    114   Field.FieldType := TFieldType(ComboBoxType.ItemIndex);
    115   if Field.FieldType = ftString then
    116     TFieldString(Field.TypeRelated).DefaultValue := EditStringDefault.Text;
    117   if Field.FieldType = ftDateTime then begin
    118     TFieldDateTime(Field.TypeRelated).Min := DateEditMin.Date;
    119     TFieldDateTime(Field.TypeRelated).Max := DateEditMax.Date;
    120   end;
    121   if Field.FieldType = ftInteger then begin
    122     TFieldInteger(Field.TypeRelated).Min := SpinEditMin.Value;
    123     TFieldInteger(Field.TypeRelated).Max := SpinEditMax.Value;
    124   end;
    125   if Field.FieldType = ftFloat then begin
    126     TFieldFloat(Field.TypeRelated).Min := FloatSpinEditMin.Value;
    127     TFieldFloat(Field.TypeRelated).Max := FloatSpinEditMax.Value;
     132  Field.DataType := TDataType(ComboBoxType.Items.Objects[ComboBoxType.ItemIndex]);
     133  case Field.DataType.FieldType of
     134    ftString: TFieldString(Field.TypeRelated).DefaultValue := EditStringDefault.Text;
     135    ftDateTime: begin
     136      TFieldDateTime(Field.TypeRelated).Min := DateEditMin.Date;
     137      TFieldDateTime(Field.TypeRelated).Max := DateEditMax.Date;
     138    end;
     139    ftInteger: begin
     140      TFieldInteger(Field.TypeRelated).Min := SpinEditMin.Value;
     141      TFieldInteger(Field.TypeRelated).Max := SpinEditMax.Value;
     142    end;
     143    ftFloat: begin
     144      TFieldFloat(Field.TypeRelated).Min := FloatSpinEditMin.Value;
     145      TFieldFloat(Field.TypeRelated).Max := FloatSpinEditMax.Value;
     146    end;
    128147  end;
    129148end;
Note: See TracChangeset for help on using the changeset viewer.