Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003510 [JEDI VCL] 00 JVCL Components feature always 2006-02-14 13:28 2006-06-08 08:04
Reporter Arioch View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0003510: 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: 1@talkto.net">news://forums.talkto.net/dsoc8r$21j$1@talkto.net [1@talkto.net" target="_blank">^]
* 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================
Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0008975)
obones (administrator)
2006-04-05 06:34

What does this do?
(0009134)
Arioch (developer)
2006-04-18 16:35

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
(0009493)
obones (administrator)
2006-06-08 08:04

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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker