?
Solved

Problem with TRichEdit changing font of SelText

Posted on 2003-02-24
9
Medium Priority
?
860 Views
Last Modified: 2013-12-03
Hi,

What I am trying to do is to create "telnet screen" in delphi which supports ansi color codes (ESC-31m etc). Font of the component is set to Courier with fixed pitch.

What I have done is to make a descendant class from TRichEdit and I am displaying text on that with such code:

procedure TCTScreen.SetSisendRida(SisendString: String);
var l:integer;
    v2rv, tekst: String;
begin
  //add new input to the current buffer (yes, it should be stream .p)
  FInputString:=FInputString+SisendString;

  //show only full lines
  if (Length(FInputString)>0) and (FInputString[length(FInputString)] in [#10, #13]) then
  Begin
    //move to the end of current text
    SelStart:=GetTextLen;
    //reset tekst, this variable will contain the current line to show
    tekst:='';

    while Length(FInputString) > 0 do
    Begin
      //for escape code..
      if FInputString[1]=#27 then
      Begin
        l:=1;
        v2rv:='';
        //basically, collecting the color code from line
        repeat
          inc(l);
          v2rv:=v2rv+FInputString[l+1];
        until (IsAlpha(FInputString[l])=True) or (l=6);
        Delete(FInputString,1,l+1);
        //dump collected text as selection to screen
        SelText:=tekst;
        //change color of text based on color code
        SelAttributes.Color:=(Ansi_V2rv(v2rv));
        //empty collector string
        tekst:='';
      End;
      //basically skip down to next color code and dump the full lines to screen meanwhile
      if length(FInputString)>0 then
      Begin
        if FInputString[1]<>#27 then
        Begin
          if FInputString[1]<>#10 then
          Begin
            tekst:=tekst+FInputString[1];
            if FInputString[1]=#13 then
            Begin
              SelStart:=GetTextLen;
              SelText:=tekst;
              SendMessage(Handle,WM_VSCROLL,SB_BOTTOM,0);
              tekst:='';
            End;
          End;
          delete(FInputString,1,1);
        End;
      End;
    End;

    //dump the last part of input
    if (tekst<>'') and (tekst<>#$A) then
    Begin
      SelStart:=GetTextLen;
      SelText:=tekst;
    End;
  End;
end;



Anyway, the problem is that every time i change the selattributes.color, the font changes as well, at least it is not Courier anymore. I have tried to set Selattributes.Name and pitch without any effect.

So, if anyone could give me a hint of what i am doing wrong here, then it would be appreciated :)
0
Comment
Question by:Cir
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:msa2003
ID: 8009624
Could you provide acces to complete source?
0
 

Author Comment

by:Cir
ID: 8009747
http://www.chaos.ee/CTScreen.zip

SetSisendRida is the function called with new input string.
0
 

Author Comment

by:Cir
ID: 8009816
http://www.chaos.ee/CTScreen.zip

SetSisendRida is the function called with new input string.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Cir
ID: 8009841
Geez, I hate refresh :)
0
 
LVL 5

Expert Comment

by:msa2003
ID: 8010401
Yes... I asked for the complete source including dpr and dfm's to. I just wont to compile and debug it...
0
 

Author Comment

by:Cir
ID: 8011275
The full project code wouldnt compile for you anyway, as it depends on too many different components and running it needs specific system setup. You can install this component and place it on a form, but this is quite much it. There is nothing wrong with anything outside this component.

The problem is, that setting selattributes.color to something _sometimes_ resets the selected text font as well. I have saved the contents of screen into the textfile, and in my system it somehow resets to Tahoma font. Is it caused by any trichedit glitch i havent found yet or am i doing something completely wrong is what i try to find out :)

So, maybe you can tell me:
1)What can cause richedit to change the font?
2)Is there any automation that can override the design time font setting?
3)Do you see anything which can trigger change of font in this code?
0
 
LVL 5

Accepted Solution

by:
msa2003 earned 300 total points
ID: 8018629
2) SelAttributes.Name := 'Courier';
DefAttributes.Name := 'Courier';
3) Try the following:

SelStart := GetTextLen;
SelAttributes.Color := Ansi_V2rv(v2rv);
SelText := tekst;
SelLength := 0;

First change selected text attributes, the next insert the text.
0
 

Author Comment

by:Cir
ID: 8141970
Hei all,

The reason for this behaviour was that Courier is not TrueType font. Using Truetype did solve, or at least hide the problem. I will award the points to msa2003 for patience .)

Cir.
0
 
LVL 5

Expert Comment

by:msa2003
ID: 8142806
It is strange... just because in most Windows systems Courier is a name of a TrueType font.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question