Changeset 14 for trunk/UDatabase.pas


Ignore:
Timestamp:
Mar 22, 2018, 7:59:13 PM (6 years ago)
Author:
chronos
Message:
  • Added: Support for item references.
  • Added: Data and Time value types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDatabase.pas

    r13 r14  
    1717
    1818  TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage,
    19     ftDate, ftTime, ftMapPosition);
     19    ftDate, ftTime, ftMapPosition, ftReference);
    2020
    2121  { TValue }
     
    2424    procedure Assign(Source: TValue); virtual;
    2525    function GetString: string; virtual;
    26     function SetString(Value: string): string; virtual;
     26    procedure SetString(Value: string); virtual;
     27    function GetStringSQL: string; virtual;
     28    procedure SetStringSQL(Value: string); virtual;
    2729  end;
    2830
     
    151153    Id: Integer;
    152154    Name: string;
     155    Title: string;
    153156    FieldType: TFieldType;
    154157    FieldTypeClass: TFieldTypeSpecificClass;
     
    158161
    159162  TDataTypes = class(TObjectList)
    160     function RegisterType(Id: Integer; Name: string; FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType;
     163    function RegisterType(Id: Integer; Name, Title: string;
     164      FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType;
    161165    function FindByType(FieldType: TFieldType): TDataType;
     166    function FindByName(Name: string): TDataType;
    162167  end;
    163168
     
    272277{ TDataTypes }
    273278
    274 function TDataTypes.RegisterType(Id: Integer; Name: string; FieldType: TFieldType;
    275   FieldTypeClass: TFieldTypeSpecificClass): TDataType;
     279function TDataTypes.RegisterType(Id: Integer; Name, Title: string;
     280  FieldType: TFieldType; FieldTypeClass: TFieldTypeSpecificClass): TDataType;
    276281begin
    277282  Result := TDataType.Create;
    278283  Result.Id := Id;
    279284  Result.Name := Name;
     285  Result.Title := Title;
    280286  Result.FieldType := FieldType;
    281287  Result.FieldTypeClass := FieldTypeClass;
     
    289295  I := 0;
    290296  while (I < Count) and (TDataType(Items[I]).FieldType <> FieldType) do Inc(I);
     297  if I < Count then Result := TDataType(Items[I])
     298    else Result := nil;
     299end;
     300
     301function TDataTypes.FindByName(Name: string): TDataType;
     302var
     303  I: Integer;
     304begin
     305  I := 0;
     306  while (I < Count) and (TDataType(Items[I]).Name <> Name) do Inc(I);
    291307  if I < Count then Result := TDataType(Items[I])
    292308    else Result := nil;
     
    408424end;
    409425
    410 function TValue.SetString(Value: string): string;
    411 begin
    412 
     426procedure TValue.SetString(Value: string);
     427begin
     428
     429end;
     430
     431function TValue.GetStringSQL: string;
     432begin
     433  Result := '';
     434end;
     435
     436procedure TValue.SetStringSQL(Value: string);
     437begin
    413438end;
    414439
     
    470495  NewRecord: TRecord;
    471496  NewValue: TValue;
     497  Index: Integer;
    472498begin
    473499  Records.Clear;
     
    478504    for F := 0 to Fields.Count - 1 do begin
    479505      NewValue := TField(Fields[F]).GetValueClass.Create;
    480       NewValue.SetString(TDictionaryStringString(DbRows[I]).Values[TField(Fields[F]).Name]);
    481       NewRecord.Values.Add(NewValue);
     506      Index := TDictionaryStringString(DbRows[I]).SearchKey(TField(Fields[F]).Name);
     507      if Index <> -1 then begin
     508        NewValue.SetString(TDictionaryStringString(DbRows[I]).Values[TField(Fields[F]).Name]);
     509        NewRecord.Values.Add(NewValue);
     510      end else begin
     511        //NewValue.SetString('');
     512        NewRecord.Values.Add(NewValue);
     513      end;
    482514    end;
    483515    Records.Add(NewRecord);
Note: See TracChangeset for help on using the changeset viewer.