Welcome, Guest
Guest Settings
Help

Thread: FilterOnBookmarks


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 28, 2017 7:59 AM Last Post By: Ilya Nenashev Threads: [ Previous | Next ]
Alexander Popov

Posts: 52
Registered: 7/22/05
FilterOnBookmarks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2017 5:20 AM
Hi!

I have an old application which always worked fine. Recently it started to throw EAccessViolation exception in method FilterOnBookmarks. I don't know when it started, maybe when I rebuild it under XE 10.1.

 
procedure TCustomADODataSet.FilterOnBookmarks(Bookmarks: array of const);
var
  I: Integer;
  BookmarkData: OleVariant;
begin
  CheckBrowseMode;
  BookmarkData := VarArrayCreate([Low(Bookmarks), High(Bookmarks)], varVariant);
  for I := Low(Bookmarks) to High(Bookmarks) do
     BookmarkData[I] := POleVariant(TVarRec(Bookmarks[I]).VPointer)^;
  inherited SetFilterText('');
  FFilterGroup := fgUnassigned;
  DestroyLookupCursor;
  try
    Recordset.Filter := BookmarkData; //<---- Here I get EAccessViolation
 
    First;
    inherited SetFiltered(True);
  except
    inherited SetFiltered(False);
    raise;
  end;
end;


I create Bookmarks parameter of FilterOnBookamrks method as an array of TVarRec:


type TSQLVarRecArray = array of TVarRec;
 
 
PBookmark = ^TBookmark;
 
TSQLBookmarkList = class(TList)
  private
 ...   
  protected
    function Get(Index: Integer): PBookmark;
  public
...
    procedure Add(Bookmark: TBookmark);
    property Items[Index: Integer]: PBookmark read Get; default;
    function ToVarRecArray: TSQLVarRecArray;
  end;
 
procedure TSQLBookmarkList.Add(Bookmark: TBookmark);
var PB: PBookmark;
    L: Integer;
begin
  New(PB);
  L := Length(Bookmark);
  SetLength(PB^, L);
  PB^ := Copy(Bookmark, 0, L);
  inherited Add(PB);
end;
 
 
function TSQLBookmarkList.ToVarRecArray: TSQLVarRecArray;
var I: Integer;
begin
  SetLength(Result, Count);
  for I := 0 to Count - 1 do begin
    Result[I].VType := vtPointer;
    Result[I].Vpointer := Items[I]^;
  end;
end; 
 


try
  ...
  Arr := BookmarkList.ToVarRecArray;
  FilterOnBookmarks(Arr);
finally
  Arr := nil; //<--- Now I get here EVariantArrayLockedError "Variant or safe array is locked"
end;
 


This code has been working for years. Has anything changed in 10.1 XE concerning with FilterOnBookmarks, Bookmarks, etc. Or maybe any changes in mdac?
Ilya Nenashev

Posts: 1
Registered: 5/24/01
Re: FilterOnBookmarks  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 28, 2017 7:59 AM   in response to: Alexander Popov in response to: Alexander Popov
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02