Recent

Author Topic: [EXAMPLE] TRichMemo High Lighted text with height exaggeration for better view  (Read 440 times)

What I can do

  • Full Member
  • ***
  • Posts: 143
OS: Windows 10@64
Compiler: Lazarus 3.4
Project: When text search is found and high lighted make more visible
logic
 capture the seltext font attributes just before high light of a search
 change that high lighted font attribute like size, color, and background color
 show that high lighted text with the new temp attributes
 and pause the search
 but when continue to the next search restore all those attribute (which I think is already the default)
 then repeat if another occurrence is found

The desired effect is the high light is Red background, with white text, and at least 20 font height
Tring to make the high light more noticeable

Code: Pascal  [Select][+][-]
  1.  Function TForm1.RMS(aRM:TRichMemo;SStr:String;AskSWH:Boolean=false):Boolean;
  2.  begin
  3.   //StartPos is 0;
  4.   FindLength:=Length(SStr);
  5.   Result:=false;
  6.  
  7.   While aRM.Search(SStr,StartPos,Length(aRM.rtf),[],StartPos,FindLength) do
  8.    begin
  9.     aRM.SelStart := StartPos;
  10.     aRM.SelLength := FindLength;
  11.     Result:=TRUE;
  12.     if AskSWH then
  13.       if NOT (MessageDlg(HLPQuery.FieldByName('H_Cat').AsAnsiString, HLPQuery.FieldByName('H_Item').AsAnsiString+#13+
  14.                                                                      HLPQuery.FieldByName('H_Sec').AsAnsiString+#13+
  15.                                                                      HLPQuery.FieldByName('H_Par').AsAnsiString+#13+
  16.                                                                      HLPQuery.FieldByName('H_Dat').AsAnsiString+#13+'Next?',mtConfirmation, [mbYes, mbNo], 0) in [mrYes,mrOK])
  17.       then break;
  18.     StartPos := StartPos + FindLength;
  19.    end;
  20.    if AskSWH then
  21.      if StartPos = -1 then
  22.       begin
  23.        if HLPQuery.RecNo<> hlpQuery.RecordCount
  24.        then
  25.         begin
  26.          HLPQuery.Next;
  27.          StartPos := 0;
  28.          RMS(aRM,SStr,AskSWH); //recursive
  29.         end;
  30.       end;
  31.  end;
  32.  

Yes I know the line "      then break;" will leave memory issues but that I can fix once I get the High light working
« Last Edit: February 02, 2025, 01:13:58 am by What I can do »

What I can do

  • Full Member
  • ***
  • Posts: 143
Re: TRichMemo High Lighted text
« Reply #1 on: February 02, 2025, 01:12:46 am »
update 2/1/2025
It took a rewrite
but here is the logic flow
frist click the [Find] button to produce the onclik
Code: Pascal  [Select][+][-]
  1.   procedure TForm1.SpeedButton4Click(Sender: TObject); //== [Next]
  2.   begin
  3.    SStr:=Edit1.Text;
  4.    FindLength:=Length(SStr);
  5.    if FindLength>0
  6.    then
  7.     begin
  8.      HlpMemuUP; //move a pig panel out of the way
  9.      Panel7.Visible:=TRUE; //makes a small control panel Visible
  10.      StartPos:=0;
  11.      FindRich; // launch the find process
  12.     end
  13.    else ShowMSG('No search data in [Titles]_______[Document]');
  14.   end;
  15.  

FindRich is fairly basic

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.FindRich;
  2. begin
  3.  SetFindOption;  //soWholeword soMatchcase  switches
  4.  if RichMemo1.Search(SStr,StartPos,Length(RichMemo1.rtf),sopt,StartPos,FindLength) //StartPos is a Global integer variable
  5.  then
  6.   begin
  7.    RichMemo1.SelStart:=StartPos;
  8.    RichMemo1.SelLength:=FindLength;
  9.    RichMemo1.GetTextAttributes(StartPos,SFp);
  10.    Tfp:=Sfp;
  11.    TFP.Size:=24;
  12.    RichMemo1.SetTextAttributes(Startpos,FindLength,Tfp);
  13.   end
  14.  else NextFindRecord;
  15.  
  16. end;
  17.  

Reset the variables and follows the loop of the next search match
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.NextFindRecord;
  2. begin
  3.   if HLPQuery.RecNo <> HLPQuery.RecordCount
  4.   then
  5.    begin
  6.     HLPQuery.Next;
  7.     StartPos:=0;
  8.     FindRich; // repeat of the nested loop
  9.    end
  10.   else ShowMSG('No more records');
  11. end;

 

TinyPortal © 2005-2018