Changeset 24 for trunk/UDatabase.pas


Ignore:
Timestamp:
Mar 26, 2018, 11:37:46 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Improved handling of SQL commands by XML backend.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDatabase.pas

    r23 r24  
    8585    Parent: TTable;
    8686    Values: TValues;
     87    function Match(AValues: TStrings): Boolean;
    8788    procedure InitValues;
    8889    procedure Assign(Source: TRecord);
     
    9798    procedure Assign(Source: TRecords);
    9899    function SearchByValue(Name, Value: string): TRecord;
     100    function SearchByValues(Values: TStrings): TRecord;
    99101    function AddNew: TRecord;
    100102  end;
     
    257259  STypeDateTime = 'Date and time';
    258260  STypeReference = 'Reference';
     261  SFieldNotFound = 'Field %s not found';
    259262
    260263
     
    607610end;
    608611
     612function TRecords.SearchByValues(Values: TStrings): TRecord;
     613var
     614  I: Integer;
     615begin
     616  Result := nil;
     617  I := 0;
     618  while (I < Count) and (TRecord(Items[I]).Match(Values)) do Inc(I);
     619  if I < Count then Result := TRecord(Items[I])
     620    else Result := nil;
     621end;
     622
    609623function TRecords.AddNew: TRecord;
    610624begin
     
    651665
    652666{ TRecord }
     667
     668function TRecord.Match(AValues: TStrings): Boolean;
     669var
     670  I: Integer;
     671  Field: TField;
     672  FieldIndex: Integer;
     673begin
     674  Result := True;
     675  for I := 0 to aValues.Count - 1 do begin
     676    Field := Parent.Fields.SearchByName(AValues.Names[I]);
     677    FieldIndex := Parent.Fields.IndexOf(Field);
     678    if Assigned(Field) then begin
     679      if TValue(Values[FieldIndex]).GetString <> AValues.ValueFromIndex[I] then begin
     680        Result := False;
     681        Break;
     682      end;
     683    end else raise Exception.Create(Format(SFieldNotFound, [AValues.Names[I]]));
     684  end;
     685end;
    653686
    654687procedure TRecord.InitValues;
Note: See TracChangeset for help on using the changeset viewer.