Jump to content


Photo

find text


  • Please log in to reply
2 replies to this topic

#1 d6user

d6user
  • Members
  • 94 posts

Posted 21 September 2014 - 11:39 PM

hi, i was searching for a solution to find text in a grid and learned there is a nextgrid.findtext(index, string,[options]) function.

http://www.bergsoft....?showtopic=4245

however it only returns a boolean, but the post (in above link) says you can use the LastFoundRow property, but i am using v5.5 and that property does not seem to be found. i can see the following properties when i type "nextgrid."

LastAddRow;
LastRow;
LastRowInView;
LastVisiblerow;

i am still using v5.5 of the nextgrid suite and not ready for upgrading yet. but if v5.5 does not have it, is there any way i can manually add it to the declarations section of NxCustomGrid.pas or to my form1 project ?

function TNxCustomGrid.FindText(const Index: Integer; S: WideString;
Options: TSearchOptions): Boolean;
begin
Result := False;
if RowCount = 0 then Exit;
if soFromSelected in Options then
begin
Result := Locate(Index, SelectedRow + 1, RowCount - 1, S, Options);
if not Result and (soContinueFromTop in Options) then Locate(Index, 0, RowCount - 1, S, Options);
end else Result := Locate(Index, 0, RowCount - 1, S, Options);
end;


#2 d6user

d6user
  • Members
  • 94 posts

Posted 22 September 2014 - 01:23 AM

solved

i'm sure there is an easier and quicker way of adding a new Property varible, but after searching around on google for how to do such things (i've never done it, and don't know where to start) and not finding any answers, and i can't wait here, for an answer, i decided to search around for an alternative answer, and i found one way that works well for my use. this is a broot force method of manually adding a global 'LastFoundRow' variable to the nextgrid v5.5 project.

later versions past v5.5 may already have the LastFoundRow Property in the code/component.

here are the steps to manually adding a global LastFoundRow variable to the nextgrid v5.5 package only. this is assuming that your nextgrid version has the 'nextgrid.findtext()' function, otherwise it won't work.

1. in your main unit1 project, scroll down to the section just past the main interface section and add the following: 'LastFoundRow: integer;' see below.

interface

type
  TNotifyEvent = procedure (Sender: TObject) of object;
  TForm1 = class(TForm)
.
.
end;
.
.
var
  LastFoundRow: integer; // <-- this line is custom added to the unit1, 2014-09-21 sun 05:45pm
  Form1: TForm1;
.
.

2. next, locate and open the 'NxCustomGrid.pas' file inside your unit1 project.
3. and enter the unit name from your main project into the uses clause. in my case, it is the default, 'Unit1', under the implementation section, like this:


implementation

uses
  unit1, NxColumnClasses, NxScrollControl, NxEdit, DateUtils, Math; // <-- custom added new line, 2014-09-21 sun


4. still in this file, scroll down to the section 'function TNxCustomGrid.Locate' and add the following line: 'LastFoundRow := i;' near the end of that function.

here is the complete updated function:

function TNxCustomGrid.Locate(Index, FromRow, ToRow: Integer; S: WideString;
  Options: TSearchOptions): Boolean;
var
  i: Integer;
begin
  Result := False;
    for i := FromRow to ToRow do
  begin
    if (soSearchInvisible in Options) or GetRowVisible(i) then
  begin
    if soCaseInsensitive in Options then
  begin
    if soExactMatch in Options then Result := WideCompareText(Cells[Index, i], S) = 0
    else Result := Pos(WideLowerCase(S), WideLowerCase(Cells[Index, i])) > 0;
  end else
  begin
    if soExactMatch in Options then Result := WideCompareStr(Cells[Index, i], S) = 0
    else Result := Pos(S, Cells[Index, i]) > 0;
  end;
  if Result then
  begin
    SelectedRow := i;
    if not IsUpdating then ScrollToRow(i);
    Break;
  end;
  end; { invisible }
  end; { for }
  LastFoundRow := i; // <-- this line is custom added 2014-09-21 sun 05:45pm
end;

5. recompile all, finish.

here is how to use:

if nextgrid1.FindText(1, 'my text', [soContinueFromTop]) = true then do_something;


#3 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 26 September 2014 - 09:51 PM

It's in 5.9.9, I just checked.

Here's how it's implemented there.

NxCustomGrid.pas
TNxCustomGrid = class(TNxCustomGridControl)
private
...
FLastFoundRow: Integer;
public
...
property LastFoundRow: Integer read FLastFoundRow;
...

constructor TNxCustomGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
...
FLastFoundRow := -1; //add the assignment somewhere in the constructor
...
end

function TNxCustomGrid.Locate(Index, FromRow, ToRow: Integer; S: WideString;
  Options: TSearchOptions): Boolean;
var
  i: Integer;
begin
  Result := False;
  for i := FromRow to ToRow do
  begin
    if (soSearchInvisible in Options) or GetRowVisible(i) then
    begin
	  if soCaseInsensitive in Options then
	  begin  
	    if soExactMatch in Options then Result := WideCompareText(Cells[Index, i], S) = 0
	    else Result := Pos(WideLowerCase(S), WideLowerCase(Cells[Index, i])) > 0;
	  end else
	  begin
	    if soExactMatch in Options then Result := WideCompareStr(Cells[Index, i], S) = 0
	    else Result := Pos(S, Cells[Index, i]) > 0;;
	  end;
	  if Result then
	  begin
	    SelectedRow := i;
	    FLastFoundRow := i;
	    if not IsUpdating then ScrollToRow(i);
	    Break;
	  end;
    end; { invisible }
  end; { for }
end;

function TNxCustomGrid.LocateByRow(Indices: array of integer; FromRow,
  ToRow: Integer; S: WideString; Options: TSearchOptions): Boolean;
var
  i, a, b: Integer;
begin
  Result := False;
  for i := FromRow to ToRow do
  begin
	    for a := 0 to Length(Indices)-1 do
	    begin
		  b := Indices[a];
		  if (b < 0) or (b > RowCount-1) then
			    Break;
		  if (soSearchInvisible in Options) or GetRowVisible(i) then
		  begin
			    if soCaseInsensitive in Options then
			    begin
				  if soExactMatch in Options then Result := WideCompareText(Cells[b, i], S) = 0
				  else Result := Pos(WideLowerCase(S), WideLowerCase(Cells[b, i])) > 0;
			    end else
			    begin
				  if soExactMatch in Options then Result := WideCompareStr(Cells[b, i], S) = 0
				  else Result := Pos(S, Cells[b, i]) > 0;;
			    end;
			    if Result then
			    begin
				  SelectedRow := i;
				  FLastFoundRow := i;
				  if not IsUpdating then ScrollToRow(i);
				  Exit;
			    end;
		  end; { invisible }
	    end;
  end; { for }
end;





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users