Link to home
Start Free TrialLog in
Avatar of Cir
Cir

asked on

Problem with TRichEdit changing font of SelText

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 :)
Avatar of msa2003
msa2003

Could you provide acces to complete source?
Avatar of Cir

ASKER

http://www.chaos.ee/CTScreen.zip

SetSisendRida is the function called with new input string.
Avatar of Cir

ASKER

http://www.chaos.ee/CTScreen.zip

SetSisendRida is the function called with new input string.
Avatar of Cir

ASKER

Geez, I hate refresh :)
Yes... I asked for the complete source including dpr and dfm's to. I just wont to compile and debug it...
Avatar of Cir

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of msa2003
msa2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cir

ASKER

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.
It is strange... just because in most Windows systems Courier is a name of a TrueType font.