View Issue Details

IDProjectCategoryView StatusLast Update
0006195JEDI VCL00 JVCL Componentspublic2014-12-04 16:32
ReporterjdresslerAssigned Toobones 
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionsuspended 
Product Version3.47 
Target VersionFixed in Version 
Summary0006195: TJvDBUltimGrid Search without result causes access violation
Description============= Old routine, without calling SaveGridPosition(); ================

function TJvDBUltimGrid.Search(const ValueToSearch: Variant; var ResultCol: Integer;
  var ResultField: TField; const CaseSensitive, WholeFieldOnly, Focus: Boolean): Boolean;
begin
  Result := False;
  if (SearchFields.Count > 0) and (ValueToSearch <> Null) and (ValueToSearch <> '') then
  begin
    FValueToSearch := ValueToSearch;
    Result := PrivateSearch(ResultCol, ResultField, CaseSensitive, WholeFieldOnly, False);
    if Result then
    begin
      Self.Col := ResultCol;
      if Focus and Self.Visible and Self.CanFocus then
        Self.SetFocus;
    end
    else
      RestoreGridPosition;
  end;
end;

============= New Routine, fixed, with SaveGridPosition ======================
function TJvDBUltimGrid.Search(const ValueToSearch: Variant; var ResultCol: Integer;
  var ResultField: TField; const CaseSensitive, WholeFieldOnly, Focus: Boolean): Boolean;
begin
  Result := False;
  if (SearchFields.Count > 0) and (ValueToSearch <> Null) and (ValueToSearch <> '') then
  begin
    FValueToSearch := ValueToSearch;
    SaveGridPosition();
    Result := PrivateSearch(ResultCol, ResultField, CaseSensitive, WholeFieldOnly, False);
    if Result then
    begin
      Self.Col := ResultCol;
      if Focus and Self.Visible and Self.CanFocus then
        Self.SetFocus;
    end
    else
      RestoreGridPosition;
  end;
end;
Additional InformationAlso note it might be wise to add nil check to RestoreGridPosition()

eg.'(FSavedBookmark<>nil) and'

procedure TJvDBUltimGrid.RestoreGridPosition(Mode: TResyncMode = [rmExact, rmCenter]);
begin
  if Assigned(FOnRestoreGridPosition) then
  begin
    if DataLink.DataSet.BookmarkValid(Pointer(FSavedBookmark)) then
      GotoBookmarkEx(DataLink.DataSet, Pointer(FSavedBookmark), [rmExact], False);

    DataLink.ActiveRecord := FSavedRowPos;
    FOnRestoreGridPosition(Self, Pointer(FSavedBookmark), FSavedRowPos);
  end
  else
  if (FSavedBookmark<>nil) and DataLink.DataSet.BookmarkValid(Pointer(FSavedBookmark)) then
    GotoBookmarkEx(DataLink.DataSet, Pointer(FSavedBookmark), Mode, False);
end;
TagsNo tags attached.

Activities

Arioch

2013-08-31 13:36

developer   ~0020617

Can you please make a demo project reproducing an error ?

obones

2013-12-13 11:45

administrator   ~0020800

Any news?

obones

2014-12-04 16:32

administrator   ~0021116

No news, suspending the issue

Issue History

Date Modified Username Field Change
2013-08-31 05:15 jdressler New Issue
2013-08-31 13:36 Arioch Note Added: 0020617
2013-08-31 13:36 Arioch Status new => feedback
2013-12-13 11:45 obones Note Added: 0020800
2014-12-04 16:32 obones Note Added: 0021116
2014-12-04 16:32 obones Status feedback => resolved
2014-12-04 16:32 obones Resolution open => suspended
2014-12-04 16:32 obones Assigned To => obones