use SelAttributes instead of DefAttributes and it will do what you want...
eg. while typing, and nothing is selected, if you do
RichEdit1.SelAttributes.St
then from that point on, your typing will be bold
if you do
RichEdit1.SelAttributes.St
then from that point on, your typing will not be bold
This should suffice for what you want.
Main Topics
Browse All Topics





by: JohnjcesPosted on 2008-01-07 at 11:03:38ID: 20602040
The Delphi Rich Edit (memo) is pretty basic and there is some functionality that is not there.
.net/ OpenSource and free.
You will notice that the RichEdit uses SelAttributes and DefAttributes.
SelAttributes are those applied to selected text. DefAttribute are those default attributes.
In the demo function
function TMainForm.CurrText: TTextAttributes;
begin
if Editor.SelLength > 0 then Result := Editor.SelAttributes
else Result := Editor.DefAttributes;
end;
Is where the attributes are found and applied. If you select text then the text attributes i.e. bold or italic etc, are applied to that text which is selected when you clcik a button, i.e. bold.
If your cursor is anywhere in the rich edit then since nothing is selected, the default attributes are changed. You can see where this is called in the example when you click on the bold or italic (and etc. ) buttons. Default is just that, all text attributes. Text that was already selected and bolded will continue to be bolded but any other click on Bold will do nothing until some text is highlighted.
With those two text attributes being defined and without doing a new rich edit component, the stock Delphi component cannot do that, (with a lot of extra code sure... maybe).
You might look at some other Rich Edit replacements that do a lot more.
One is SynEdit. http://synedit.sourceforge
Search Torry.net and DelphiPages.com for other rich edits memos.
Hope I helped.
John