View Issue Details

IDProjectCategoryView StatusLast Update
0003510JEDI VCL00 JVCL Componentspublic2006-06-08 08:04
ReporterAriochAssigned Toobones 
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
PlatformDelphi 5 EntOSwin ntOS Version2000 sp4
Product Version 
Target VersionFixed in Version3.30 
Summary0003510: quick and perhaps ugly Lookup for TJvMemoryData
Description==========================================================================
* Forwarded by Arioch /BDV/
* Newsgroup: jedi.vcl on: forums.talkto.net
* From: "Arioch /BDV/" <the_Arioch@nm.False-Domain.ru>
* Date: Mon, 13 Feb 2006 01:28:32 +0300
* URL: news://forums.talkto.net/dsoc8r$21j$1@talkto.net
* Subj: quick and perhaps ugly Lookup for TJvMemoryData
==========================================================================

Hello, All!

cloned from JvDBUtils.pas

perhaps it is not very effecient to create and dispose TList on every call -
but at least it should not be worse, than TJvMemoryData.Lookup :)
Those lists may be cached for example, or something better can be implemented perhaps. Internals of TDataSet seemss not to be documented :(

=========Beginning of the citation==============
function TJvMemoryData.Lookup(const KeyFields: string;
  const KeyValues: Variant; const ResultFields: string): Variant;
var
  FieldCount: Integer;
  Fields: TList;
  Fld: TField; {BG} //else BAD mem leak on
'Field.asString'
// Bookmark: TBookmarkStr;
  SaveState: TDataSetState;
  i: integer;
  Matched: boolean;

  function CompareField(var Field: TField; Value: Variant): Boolean; {BG}
  var
    S: string;
  begin
    if Field.DataType = ftString then
    begin
      if Value = Null then
        Result := Field.IsNull
      else
      begin
        S := Field.AsString;
        Result := AnsiSameStr(S, Value);
      end;
    end
    else
      Result := (Field.Value = Value);
  end;

  function CompareRecord: Boolean;
  var
    I: Integer;
  begin
    if FieldCount = 1 then
    begin
      Fld := TField(Fields.First); {BG}
      Result := CompareField(Fld, KeyValues) {BG}
    end
    else
    begin
      Result := True;
      for I := 0 to FieldCount - 1 do
      begin
        Fld := TField(Fields[I]); {BG}
        Result := Result and CompareField(Fld, KeyValues[I]); {BG}
      end;
    end;
  end;
begin
  Result := NULL;
  CheckBrowseMode;
    if IsEmpty then Exit;

  Fields := TList.Create;
  try
    GetFieldList(Fields, KeyFields);
    FieldCount := Fields.Count;
    Matched := CompareRecord;
    if Matched then
       Result := FieldValues[ ResultFields]
    else begin
        SaveState := SetTempState(dsCalcFields);
        try
          try
             for i := 0 to Recordcount - 1 do begin
                RecordToBuffer(Records[i], TempBuffer);
                CalculateFields(TempBuffer);
                Matched := CompareRecord;
                if Matched then
                  Break;
             end;
          finally
            if Matched then Result := FieldValues[ ResultFields];
          end;
        finally
          RestoreState(SaveState);
        end;
    end;
  finally
    Fields.Free;
  end;
end;
=========The end of the citation================
TagsNo tags attached.

Activities

obones

2006-04-05 06:34

administrator   ~0008975

What does this do?

Arioch

2006-04-18 16:35

developer   ~0009134

implements TJvMemoryData.Lookup

In one of my projects i use 4 TJvMemoryData components, and 3 of those have fields that are taken from another one, 'main' one.

It is not Master-Detial yet, but TField.Lookup* properties now seem to work with TJvMemoryData

obones

2006-06-08 08:04

administrator   ~0009493

This is now in SVN.

Issue History

Date Modified Username Field Change
2006-02-14 13:28 Arioch New Issue
2006-04-05 06:34 obones Note Added: 0008975
2006-04-05 06:34 obones Status new => feedback
2006-04-18 16:35 Arioch Note Added: 0009134
2006-06-08 08:04 obones Status feedback => resolved
2006-06-08 08:04 obones Resolution open => fixed
2006-06-08 08:04 obones Assigned To => obones
2006-06-08 08:04 obones Note Added: 0009493