- Passing the search string to a 'show blog entry' window
- Highlighting the sought-for text
sl.Text:= HTMLCode; if searchstring <> '' then for i:= 1 to sl.Count do begin aline:= sl[i - 1]; flag:= false; j:= pos (searchstring, aline); while j > 0 do begin flag:= true; s:= copy (aline, 1, j-1); aline:= copy (aline, j + length (searchstring), 200); s:= s + '<span style="background-color: yellow;"> ' + searchstring + '</span>'; j:= pos (searchstring, aline); end; if flag then sl[i - 1]:= s + aline; end; sl.SaveToStream (ms);
In the first line of the above code, the variable HTMLCode contains the raw text of the blog entry, including the various tags. I should change the line 'i:= 1 to sl.count' so that the loop starts with the second or possibly third line of the text; the opening line(s) contain the title and other text that is not displayed so there's no reason to consider them candidates for HTML insertion (it looks like the first seven lines can be skipped - this should also be applied to the code that searches for the string in the first place).
But how to pass the search string? This is complicated because of the recursive manner in which the list of blogs containing the search string is displayed; the TShowEntries window gets called by several different functions and it also calls itself. I found an elegant way of solving this problem: which ever way this window is invoked, it always receives an instance number that points to the data stored in the temp table (see here3 for an explanation). If I store the search string in these tuples, then it can be retrieved when the TShowEntries window is executed, and the search string can be passed to each 'show blog entry' window when opened.
All this took about half an hour to program and it worked first time. I admit that it could be polished but what exists is substantially correct.
Internal links
[1] 1828
[2] 1908
[3] 1548
Title | Tags | ||
---|---|---|---|
127 | Holiday week | Programming, Delphi, Cold feet | |
702 | More research | DBA | |
1024 | Jerry Lee Lewis rides again | Grandfather | |
1607 | Songbird | Song writing | |
1747 | Wishing you a happy and kosher Pesach! | Personal |
No comments:
Post a Comment