RTC Forums
May 05, 2024, 09:40:11 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: RTCMemDataSet Locate Method  (Read 3948 times)
manoi
RTC License
***
Posts: 8


« on: August 11, 2017, 06:32:46 AM »

Hi,

I've use TRTCMemDataset in mobile application (freepascal) and use it as TClientDataset replacement and it work very well but I need the locate function to work from RTCMemDataset.

Do you have any suggestion ?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: August 11, 2017, 07:28:24 AM »

Sorry, but the TRtcMemDataSet component is deprecated and I have no plans to extend it with new features. If you need anything that is NOT already implemented in the TRtcMemDataSet component and you can NOT port your project to a later Delphi version to use the TRtcClientDataSet component (which is based on TClientDataSet), you could try some other in-memory DataSet component for FreePascal to see if it better suits your needs, or ... you could write your own version of a "TRtcMemDataSet" component and implement the missing function(s) yourself.

Best Regards,
Danijel Tkalcec
Logged
manoi
RTC License
***
Posts: 8


« Reply #2 on: August 12, 2017, 04:05:21 AM »

OK. I've modify routine from JvDBUtils.DataSetLocateThrough

Code:
function DataSetLocateThrough(DataSet: TDataSet; const KeyFields: string;
  const KeyValues: Variant; Options: TLocateOptions): Boolean;
var
  FieldCount: Integer;
  Fields: TList;
  OldRecNo: Integer;

  function CompareField(Field: TField; Value: Variant): Boolean;
  var
    S: string;
  begin

    if Field.DataType = ftString then
    begin
      if Value = Null then
        Result := Field.IsNull
      else
      begin
        S := Field.AsString;
        if loPartialKey in Options then
          Delete(S, Length(Value) + 1, MaxInt);
        if loCaseInsensitive in Options then
          Result := AnsiCompareText(S, Value) = 0
        else
          Result := AnsiCompareStr(S, Value) = 0;
      end;
    end
    else
    begin
      Result := (Field.Value = Value);
    end;
  end;

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

begin



  Result := False;
  OldRecNo:=0;
  with DataSet do
  begin
    CheckBrowseMode;
    if Bof and Eof then
      Exit;
  end;
  Fields := TList.Create;
  try
    DataSet.GetFieldList(Fields, KeyFields);


    FieldCount := Fields.Count;
    Result := CompareRecord;
    if Result then
      Exit;
    DataSet.DisableControls;
    try
      OldRecNo := DataSet.Recno;
      try
        with DataSet do
        begin
          First;
          while not EOF do
          begin
            Result := CompareRecord;
            if Result then
              Break;
            Next;
          end;
        end;
      finally
        if not Result and (OldRecNo>0) then
          DataSet.RecNo := OldRecNo;
      end;
    finally
      DataSet.EnableControls;
    end;
  finally
    Fields.Free;
  end;
end;



and modify TRtcBaseDataSet.Locate to

Code:
function TRtcBaseDataSet.Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;
begin
  CheckBiDirectional;
  Result := DataSetLocateThrough(Self, KeyFields, KeyValues, Options);
  // ??
end;

Now it work.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: August 12, 2017, 07:49:59 AM »

Ok. Thank you for your feedback.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.