0

I have written a program to search for errors (according to a pattern) in the text. The error search is done programmatically from the text in SynEdit with the subsequent display of errors in StringGrid. How to make a synchronous change in the corresponding line of SynEdit when changing the text in StringGrid?

  1. Open the file in SynEdit.

  2. Create a temporary file from the text in SynEdit.

  3. Load the temporary file (FileName.tmp) into TStringlist.

  4. Searching for errors in the text from TStringlist.

  5. Filling StringGrid.

     procedure Tform1.SearchDetailErrors(Sender: TObject);
     var
       strlError: TStringlist;
       i:         integer;       
       str:       string;
     begin
       if not DirectoryExists('Duplicates & Errors') then                 
         frmMain.CreateDirDuplicates(Sender);                               
       if frmMain.SynEdit.Lines.Count >= 1 then                           
         frmMain.SynEdit.Lines.SaveToFile('Duplicates & Errors\All Erros ' +
                          ExtractFileName(frmMain.OpenTxtFileDlg.FileName) +
                                                                    '.tmp');
       strlError := TStringList.Create;                                   
       strlError.LoadFromFile('Duplicates & Errors\All Erros '  +         
               ExtractFileName(frmMain.OpenTxtFileDlg.FileName) +         
                                                         '.tmp');
       for i := 0 to strlError.Count - 1 do                               
         begin
           strlError.Strings[i] := Trim(strlError.Strings[i]);
           if CountPos('<', strlError.Strings[i])  <> 1 then               
             begin
               str := IntToStr(i + 1) + ' | <         | ' +       strlError.Strings[i];
           //str := IntToStr(i + 1) + ' < ' + strlError.Strings[i];
           StrLDupl.AddStrings(str);                             
           str := '';                                            
           CPos := 0;                                            
         end;
       if CountPos('>', strlError.Strings[i])  <> 1 then                
         begin
           str := IntToStr(i + 1) + ' | >         | ' + strlError.Strings[i];
           StrLDupl.AddStrings(str);                                   
           str := '';                                                  
           CPos := 0;                                                  
         end;
        ...
       if Odd(CountPos('!', strlError.Strings[i])) then                  
         begin
           str := IntToStr(i + 1) + ' | !         | ' + strlError.Strings[i];
           //str := IntToStr(i + 1) + ' " ' + strlError.Strings[i];
           StrLDupl.AddStrings(str);                                     
           str := '';                                                    
           CPos := 0;                                                    
         end;
       ...
       StringGridOptions(Sender);
      end;
    
      procedure Tform1.StringGridOptions(Sender: TObject);
      begin
        with SGDetailErrors do
        ... 
          begin
            Cells[0, 0]  := 'Line № ';                                              
            Cells[1, 0]  := 'Error ';                                               
            Cells[2, 0]  := 'String';                                               
          end;
        FillStringGridResultDetailErrors(Sender);
      end;
    
      procedure Tform1.FillStringGridResultDetailErrors(Sender: TObject);
      var
        strlError: TStringList;
        i:         Integer;
        s:         String;
      begin
        strlError := TStringList.Create;
        try
          strlError.LoadFromFile('Duplicates & Errors\All Errors '   +
               ExtractFileName(frmMain.OpenTxtFileDlg.FileName) +
                                                         '.txt');
     strlError.QuoteChar := #0;                                  
     for i := 0 to strlError.Count - 1 do
       begin
         with SGDetailErrors do                                              
           begin
             Rows[i + 1].Delimiter     := '|';                               
             strlError.Strings[i]      := StringReplace(strlError.Strings[i],
                                                                  ' ', 'tmp',
                                                             [rfReplaceAll]);
             Rows[i + 1].DelimitedText := strlError.Strings[i];              
             Cells[0, i]               := StringReplace(Cells[0, i],         
                                                          'tmp', '',
                                                    [rfReplaceAll]);
             Cells[1, i]               := StringReplace(Cells[1, i],         
                                                          'tmp', '',
                                                    [rfReplaceAll]);
             Cells[2, i]               := StringReplace(Cells[2, i],         
                                                         'tmp', ' ',
                                                    [rfReplaceAll]);
           end;
        end;
      except
       raise Exception.Create('Error processing file.');                       
     end;      
     strlError.Free;
    end;
    

StringGrid

1
  • Please, show your code that scans the SynEdit text for errors, and adds detected errors to the StringGrid. In order for you to make corrections into the SynEdit text, you also need to store the location (e.g. row, character) of the error, to the StringGrid. Are you doing that? Without you showing the code you have sofar, we can't help you. Commented May 29 at 6:44

1 Answer 1

1

Use the TStringGrid.Objects property, or a separate list/array, to store tracking information about each error being displayed. Such as line number, column number, and character length.

Then, when the user makes a change to a given error in the TStringGrid, use the cooresponding tracking info to update the SynEdit text accordingly, and update the tracking info of subsequent errors to account for differences in the updated text.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.