Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo formatting problems 1

Status
Not open for further replies.

ukusa

Programmer
Oct 8, 2001
49
AU
Howdy,

I have a reporting function which turns numbers into a formatted English report. The info is in RichEdit format inside a table. Then an Editor is used by the user to change font sizes, bold, Italic etc, other words formats the text to be ready for printing any way they like.

I have used the Demo in Delphi 5 to be guided by(RichEdit example) and in mine using the DBRichEdit field I, SELECT text and change to Italic / Bold etc, that works fine, reselecting that text and undo via those buttons will undo the formatting - no problem there. The problem is when I use 2 or more styles, bold it and Italic / underline etc and when I want to undo one or more of those styles, it doesn't change back and stays in Italic etc - any ideas?


Thanks
Allen
 
I had this exact problem about two weeks ago. I had a richedit with a Bold, Italic and and Underline button. I discovered the way to do this was to add extra code to each button like this.

with RichEdit1 do begin
if (SelAttributes.Style = [fsBold]) or (SelAttributes.Style = [fsBold, fsItalic])
or (SelAttributes.Style = [fsBold, fsUnderline]) or (SelAttributes.Style = [fsBold, fsItalic, fsUnderline]) then
SelAttributes.Style := SelAttributes.Style - [fsBold] else
SelAttributes.Style := SelAttributes.Style + [fsBold];
end;

I just placed an or statment for the different possibilties (ie, the way the different styles were added to the SelAttributes). Above is the code for the bold button.

This is the Italic button.

with RichEdit1 do begin
if (SelAttributes.Style = [fsItalic]) or (SelAttributes.Style = [fsItalic, fsBold])
or (SelAttributes.Style = [fsItalic, fsUnderline]) or (SelAttributes.Style = [fsItalic, fsBold, fsUnderline]) then
SelAttributes.Style := SelAttributes.Style - [fsItalic] else
SelAttributes.Style := SelAttributes.Style + [fsItalic]
end;

and this is for the underline button.

with RichEdit1 do begin
if (SelAttributes.Style = [fsUnderline]) or (SelAttributes.Style = [fsUnderline, fsBold])
or (SelAttributes.Style = [fsUnderline, fsItalic]) or (SelAttributes.Style = [fsUnderline, fsBold, fsItalic]) then
SelAttributes.Style := SelAttributes.Style - [fsUnderline] else
SelAttributes.Style := SelAttributes.Style + [fsUnderline];
end;

Hope this helps you out. Arte Et Labore
 
Thanks Arte, works brilliantly, ACE answer!!! Just hope others don't fall into that trap too.

Thanks heaps.
Allen Crisell
 
Heya guys. You're lucky that SelAttributes.Style is a set that has only 4 elements :) i mean that if it had 100 elements your "if(SelAttributes.Style = ...)or(...) then" condition would be like 10 pages long. I guess it's would be easier if you change it to something like:
Code:
  if (fsBold in SelAttributes.Style) then
   Exclude(SelAttributes.Style, fsBold)
  else
   Include(SelAttributes.Style, fsBold);
But that's just a thought. Good luck

--- markus
 
McMerfy, You make a good point. Unfortunately when I wrote the code it was gone midnight and logic was quickly deserting me. Good tip though and it is much appreciated! Arte Et Labore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top