Recent

Author Topic: RichMemo - search function  (Read 3708 times)

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
RichMemo - search function
« on: August 06, 2017, 02:30:03 pm »
I am having problems with RichMemo's Search functions. The following always sets Start to -1, ie "not found".

Code: Pascal  [Select]
  1. RichMemo1.Append('This is a link in some text');
  2. Start := RichMemo1.Search('link', 0, RichMemo1.GettextLen(), []);
  3.  

Now, I followed it through with debugger and found what seems strange to me. Please forgive me if my reasoning is flawed, thats very possible !

Looking at TCustomRichMemo.Search(....), it return -1 when TCustomRichMemo.Search(string, int, int, [], int, int) returns false.

In turn, that function's, result does not appear to be set if  TWSCustomRichMemoClass(WidgetSetClass).isSearchEx (line 1088, RichMemo.pas) returns false. In my case, it calls TWSCustomRichMemo.isSearchEx (line 368, WSRichMemo.pas) which is hard wired to return false.

Is that any help in determining whats happening ?
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo - search function
« Reply #1 on: August 06, 2017, 02:40:10 pm »
Mind you, if I call the other version of Search() directly, it works as expected. Hmm....

(that is TCustomRichMemo.Search(string, int, int, [], int, int) does work for me. )

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo - search function
« Reply #2 on: August 06, 2017, 03:10:24 pm »
No, sorry, seems to me the function is still behaving erratically when used in my main program (rather than a simplified demo).  And it still looks to me as if Result is undefined.

Right now, TCustomRichMemo.Search(string, int, int, [], int, int) : boolean   says Result is 255 just before it exits.  ??

David
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2282
    • havefunsoft.com
Re: RichMemo - search function
« Reply #3 on: August 06, 2017, 03:50:47 pm »
gtk2 Linux?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo - search function
« Reply #4 on: August 07, 2017, 01:46:01 am »
Yes, ubuntu mate, thats gtk2.  So, just tried it under Windows, quick test before I go out and it seems to work fine there, no sign of the problem. So, maybe its a Linux only issue ??

I have played some more on linux. It now seems clear to me that this is erratic. More likely to be a problem in a larger project than the simple demo.  And, the SetLink() function plays up at the same time.

I am wondering if I have some memory corruption issue ?  Perhaps need to see if I've forgotten to create() something ??

As I said earlier, the first version of Search() fails every time even in the very simple demo. The second version (that returns a bool) works fine in my demo but always returns True setting Start to 1 in a more complicated program.  SetLink() works fine in the simple demo, but has no effect in the larger app.

Hmm....
« Last Edit: August 07, 2017, 03:00:20 am by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 756
    • tomboy-ng, a rewrite of the classic Tomboy
Re: RichMemo - search function
« Reply #5 on: August 07, 2017, 10:44:46 am »
OK, I know its very unlikely but I have just about convinced myself I have found a bug in RichMemo.
Linux, GTK2, Search() functions.

As hinted above, looks like the result from f TCustomRichMemo.Search():boolean; implemented in line #1078 is not setting its result correctly. Firstly, there is a way through the function without setting it at all. Secondly, if the function TGtk2WSCustomRichMemo.Search(..): Integer; in Gtk2RichMemo, line #1436 does find the searched for string, TCustomRichMemo.Search():boolean does not set its Result to True.

I add two lines to RichMemo.pas and it passes my test.....

Firstly, insert line #1094, something to set Result if the GTK2 search works -
if ATextStart >= 0 then Result := true;

Secondly, first thing in  TCustomRichMemo.Search():boolean line #1083 insert
Result:= false;

Still have problems with Setlink() but that needs a separate thread.....

David


Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng