TadvStringGrid search

When searching the TadvStringGrid using Find() and then highlighting found text with HilightInCell() there is a problem with cells that are displaying either RTF or HTML strings:

HTML : calling HilightInCell() exposes the raw HTML to the user after the <HI> tag has been inserted, and I can't find a way to return it to normal WYSIWYG display either programmatically or in the UI itself.

RTF : calling HilightInCell() inserts <HI> tag and then the inplace RichEdit editor cannot interpret the tag so it does nothing and just spoils the text.

Am I missing something or is there a work around. As long as one of the above works I'll be happy!

TIA Paul - Navigator Systems


Sorry, HighlightInCell internally uses HTML formatting to perform the highlighting, as such it is not applicable to cell in RTF or already HTML formatted. 

OK, but it would be useful if the documentation made this clear. Also the SearchFooter UI suffers from the same problem...in fact worse, as it never clears the <HI> tags and they just keep accumulating.

Any suggestions on a workaround? I suspect I want to use HTML in the cells rather than RTF because I think the Find() doesn't have an option to ignore RTF markup text, unlike the fnIgnoreHTMLTags option. Having said that, I did try to get a handle on the InplaceRichEdit: (once a Find() had located an RTF cell ) and then use the editor's own search and SelText options, but for some reason the editor's text is always empty.

I really need to get this working somehow. Thanks

OK, I looked at the TadvStringGrid code for highlighting and it didn't take me very long to adapt a version of HiLight() for me own TAdvStringGridHilighter class. Its not 100% perfect (yet) because it doesn't work for multi word target strings where one or more of the words are marked up, but I'll get around to that later.

Anyhow, you will see from my code that either I don't understand a very obscure purpose your have for turning all the tags into literals or its a very strange thing to do indeed! By removing all your work on the tags and making a few minor adjustments, I have the highlighting working very well now. So, I am tempted to say that you've got this bit of you MOST EXCELLENT GRID wrong, and I don't think it is much of a challenge to change :)

class function TAdvStringGridHilighter.HiLight(s, h, tag : string; DoCase : boolean) : string;
 var
    hs : string;
    l, k : Integer;

 const
    tagOpenSymbolCount = 2;
    tagCloseSymbolCount = 3;
 begin
  // s = cell str
  // h = search str
  // tag = highlight tag

 //  hs := HTMLStripAll(s);

    l := 0;

//  if (pos('<',hs) >0) or (pos('>',hs) > 0) then
//  begin
//    hs := StringReplace(hs,'<','&lt;',[rfReplaceAll]);
//    hs := StringReplace(hs,'>','&gt;',[rfReplaceAll]);
//    s := hs;
//    h := StringReplace(h,'<','&lt;',[rfReplaceAll]);
//    h := StringReplace(h,'>','&gt;',[rfReplaceAll]);
//
//  end;

//  while PosFrom(h,hs,l,DoCase,k) > 0 do
    while PosFrom(h, s, l, DoCase, k) > 0 do
      begin
       l := k + Length(h) + length(tag) + tagOpenSymbolCount;
       Insert('<' + tag + '>', s, k);
       Insert('</' + tag + '>', s, l);
       l := l + length(tag) + tagCloseSymbolCount;
//    Insert('<'+tag+'>',s,StripPos2HTMLPos(s,k));
//    Insert('</'+tag+'>',s,StripPos2HTMLPos(s,l));
      end;

    Result := s;
 end;