Home > Delphi > Better status

Better status

If you are like me, then you probably use a memo when you want to have some onscreen feedback or logging. This works fine but it can be made to look prettier using a richEdit control instead. Here is a small procedure i slapped together which allows you to have Bold formated sections and tab-indent for text. Small but effective!

The code should be easy enough to expand. You may want to do “live” formating of words by hooking into the onKeyPress event, or add support for better colors.

Easier on the eyes

Easier on the eyes

procedure TForm1.Log(aText:string;
          Const Bold:Boolean=False;
          const aTab:Integer=0);
var
  mLen: Integer;
  mStart: Integer;
  TextPos: lResult;
Begin
  redtStatus.Lines.BeginUpdate;
  try
    mStart:=Length(redtStatus.Text);
    mLen:=Length(aText);

    redtStatus.SelStart:=mStart;
    redtStatus.SelLength:=0;
    redtStatus.Paragraph.FirstIndent:=aTab;

    case Bold of
    False:
      Begin
      redtStatus.SelAttributes.Color:=redtStatus.Font.Color;
      redtStatus.SelAttributes.Style:=[];
      redtStatus.SelAttributes.Name:='Courier new';
      redtStatus.SelAttributes.Size:=8;
      end;
    true:
      Begin
      redtStatus.SelAttributes.Color:=clBlue;
      redtStatus.SelAttributes.Style:=[fsBold,fsUnderline];
      redtStatus.SelAttributes.Name:=redtStatus.Font.Name;
      redtStatus.SelAttributes.Size:=11;
      end;
    end;
    redtStatus.SelText:=aText;

    redtStatus.Lines.Add('');
    redtStatus.selstart:= length(redtStatus.Text);
    redtStatus.sellength:= 0;

    SendMessage(redtStatus.Handle, WM_VSCROLL,
    MakeWParam(SB_THUMBPOSITION, $FFFF), 0);
    SendMessage(redtStatus.Handle, EM_SETSEL, TextPos, TextPos);
  finally
    redtStatus.Lines.EndUpdate;
  end;
end;
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: