title: Richedit style formatting changes on its own
body: <p>(Someone edit the title if you can understand and define my problem better.)</p>
  
  <p>The problem which I am having is with style formatting of a RichEdit "reverting" back to the default "nothing" aka <code>[]</code> and then back to whatever I set it to, bold or italic for example.</p>
  
  <p>The thing that is at fault - I assume, since I have no idea how it is breaking things - is a procedure (REMainLinesCheck) that checks for amount of lines in the RichEdit and deletes the first one until a certain point is reached (to show a maximum of 14 lines at once) like so:</p>
  
  <pre><code>while REMain.Lines.Count &gt; 14 do
    REMain.Lines.Delete(0); 
  </code></pre>
  
  <p>I have 6 occurrences of the above procedure in other procedures that add lines to the RichEdit, but none of them change <code>RichEdit.SelAttributes.Style</code> but one, which was adding only one Bold line like so:</p>
  
  <pre><code>REMain.SelAttributes.Style := [fsBold];
  REMain.Lines.Add('something');
  REMainLinesCheck;
  </code></pre>
  
  <p>So I have removed all occurrences except that one and started poking around, it didn't take long to see that it was working in fact fine, regular and bold lines where being added normally and excess lines where being deleted - no problems. But as soon as I reintroduced REMainLinesCheck procedure into another procedure (for clarity purposes, lets call it Proc3Lines, because that's what it does: adds 3 lines and then calls the check for excess lines), every line that follows this Proc3Lines that should be Bold is not... From what I have experienced here it seems that REMainLinesCheck does something in Proc3Lines, since without it everything is fine.</p>
  
  <p>Obviously it's not a circle of procedures that call each other, but the other parts of the code have nothing to do with this RichEdit, not to mention that I don't change <code>RichEdit.SelAttributes.Style</code> anywhere for REMain except that one place that I have shown, there is another RichEdit in the same unit that I do change its line's style like that, but that cannot possibly be related in any way... could it? (No it does not, I just checked.)</p>
  
  <p>Basically: what the hell Delphi? It cannot get any simpler than this and I am still managing to fail, can someone explain and/or fix this? Ask questions, I'll elaborate as much as I can if something is not clear.</p>