Archive
Archive for May 21, 2013
Better status
May 21, 2013
Leave a comment
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.
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;
You must be logged in to post a comment.