Changeset 3 for trunk/UDatabase.pas


Ignore:
Timestamp:
Jan 18, 2015, 5:25:37 PM (10 years ago)
Author:
chronos
Message:
  • Added: Support for editing String and DateTime value types in record edit form.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33MyData.lps
        44data.xml
         5Config.xml
  • trunk/UDatabase.pas

    r2 r3  
    66
    77uses
    8   Classes, SysUtils, Contnrs;
     8  Classes, SysUtils, Contnrs, ExtCtrls, StdCtrls, EditBtn;
    99
    1010type
     11  TTable = class;
     12
    1113  TFieldType = (ftString, ftNumeric, ftDateTime, ftBoolean, ftFloat, ftImage,
    1214    ftDate, tfTime, ftMapPosition);
    1315
     16  { TValue }
     17
     18  TValue = class
     19    function GetString: string; virtual;
     20  end;
     21
     22  TValueClass = class of TValue;
     23
     24  { TValueString }
     25
     26  TValueString = class(TValue)
     27    Value: string;
     28    function GetString: string; override;
     29  end;
     30
     31  TValueInteger = class(TValue)
     32    Value: Integer;
     33  end;
     34
     35  { TValueDateTime }
     36
     37  TValueDateTime = class(TValue)
     38    Value: TDateTime;
     39    function GetString: string; override;
     40  end;
     41
     42  TValues = class(TObjectList)
     43  end;
     44
     45  { TFieldTypeSpecific }
     46
     47  TFieldTypeSpecific = class
     48    function GetValueClass: TValueClass; virtual;
     49  end;
     50
     51  TFieldTypeSpecificClass = class of TFieldTypeSpecific;
     52
     53  { TFieldString }
     54
     55  TFieldString = class(TFieldTypeSpecific)
     56    DefaultValue: string;
     57    function GetValueClass: TValueClass; override;
     58  end;
     59
     60  TFieldInteger = class(TFieldTypeSpecific)
     61    Min: Integer;
     62    Max: Integer;
     63    DefaultValue: Integer;
     64  end;
     65
     66  TFieldFloat = class(TFieldTypeSpecific)
     67    Min: Double;
     68    Max: Double;
     69    DefaultValue: Double;
     70  end;
     71
     72  { TFieldDateTime }
     73
     74  TFieldDateTime = class(TFieldTypeSpecific)
     75    Min: TDateTime;
     76    Max: TDateTime;
     77    function GetValueClass: TValueClass; override;
     78  end;
     79
     80  TFieldDate = class(TFieldTypeSpecific)
     81    Min: TDate;
     82    Max: TDate;
     83  end;
     84
     85   TFieldTime = class(TFieldTypeSpecific)
     86    Min: TTime;
     87    Max: TTime;
     88  end;
     89
     90  TFieldImage = class(TFieldTypeSpecific)
     91    MinSize: TPoint;
     92    MaxSize: TPoint;
     93  end;
     94
     95  TFieldBoolean = class(TFieldTypeSpecific)
     96    DefaultValue: Boolean;
     97  end;
     98
     99  TFieldMapPosition = class(TFieldTypeSpecific)
     100  end;
     101
    14102  { TField }
    15103
    16104  TField = class
     105  private
     106    FFieldType: TFieldType;
     107    procedure SetFieldType(AValue: TFieldType);
     108  public
    17109    Name: string;
    18     FieldType: TFieldType;
     110    TypeRelated: TFieldTypeSpecific;
    19111    Required: Boolean;
    20112    ReadOnly: Boolean;
     
    25117    Pos: TPoint;
    26118    Size: TPoint;
    27   end;
    28 
    29   TFieldString = class(TField)
    30     DefaultValue: string;
    31   end;
    32 
    33   TFieldInteger = class(TField)
    34     Min: Integer;
    35     Max: Integer;
    36     DefaultValue: Integer;
    37   end;
    38 
    39   TFieldDateTime = class(TField)
    40     Min: TDateTime;
    41     Max: TDateTime;
    42   end;
    43 
    44   TFieldImage = class(TField)
     119    function GetValueClass: TValueClass;
     120    property FieldType: TFieldType read FFieldType write SetFieldType;
     121    constructor Create;
    45122  end;
    46123
     
    48125  end;
    49126
    50   TValue = class
    51   end;
    52 
    53   TValueString = class
    54     Value: string;
    55   end;
    56 
    57   TValueInteger = class
    58     Value: Integer;
    59   end;
    60 
    61   TValueDateTime = class
    62     Value: TDateTime;
    63   end;
    64 
    65   TValues = class(TObjectList)
    66   end;
     127  { TRecord }
    67128
    68129  TRecord = class
     130    Parent: TTable;
    69131    Values: TValues;
     132    constructor Create;
     133    destructor Destroy; override;
    70134  end;
    71135
    72136  TRecords = class(TObjectList)
    73 
     137    Parent: TTable;
    74138  end;
    75139
     
    105169  FieldTypeString: array[TFieldType] of string = ('String', 'Numeric', 'DateTime',
    106170    'Boolean', 'Float', 'Image', 'Date', 'Time', 'MapPosition');
     171  FieldTypeClass: array[TFieldType] of TFieldTypeSpecificClass = (TFieldString,
     172    TFieldInteger, TFieldDateTime, TFieldBoolean, TFieldFloat, TFieldImage,
     173    TFieldDate, TFieldTime, TFieldMapPosition);
    107174
    108175
    109176implementation
    110177
     178{ TFieldDateTime }
     179
     180function TFieldDateTime.GetValueClass: TValueClass;
     181begin
     182  Result := TValueDateTime;
     183end;
     184
     185{ TValueDateTime }
     186
     187function TValueDateTime.GetString: string;
     188begin
     189  Result := DateTimeToStr(Value);
     190end;
     191
     192{ TRecord }
     193
     194constructor TRecord.Create;
     195begin
     196  Values := TValues.Create;
     197end;
     198
     199destructor TRecord.Destroy;
     200begin
     201  Values.Free;
     202  inherited Destroy;
     203end;
     204
     205{ TValueString }
     206
     207function TValueString.GetString: string;
     208begin
     209  Result := Value;
     210end;
     211
     212{ TValue }
     213
     214function TValue.GetString: string;
     215begin
     216  Result := '';
     217end;
     218
     219{ TFieldString }
     220
     221function TFieldString.GetValueClass: TValueClass;
     222begin
     223  Result := TValueString;
     224end;
     225
     226{ TFieldTypeSpecific }
     227
     228function TFieldTypeSpecific.GetValueClass: TValueClass;
     229begin
     230  Result := TValue;
     231end;
     232
    111233{ TField }
    112234
     235procedure TField.SetFieldType(AValue: TFieldType);
     236begin
     237  if FFieldType = AValue then Exit;
     238  if Assigned(TypeRelated) then TypeRelated.Free;
     239  FFieldType := AValue;
     240  TypeRelated := FieldTypeClass[FFieldType].Create;
     241end;
     242
     243function TField.GetValueClass: TValueClass;
     244begin
     245  if Assigned(TypeRelated) then Result := TypeRelated.GetValueClass
     246    else Result := TValue;
     247end;
     248
     249constructor TField.Create;
     250begin
     251  TypeRelated := TFieldString.Create;
     252end;
     253
     254{ TField }
     255
    113256
    114257{ TTable }
     
    117260begin
    118261  Records := TRecords.Create;
     262  Records.Parent := Self;
    119263  Fields := TFields.Create;
    120264end;
Note: See TracChangeset for help on using the changeset viewer.