Forum > Beginners

StatusBar panel DrawText special characters

(1/2) > >>

TomTom:
Hi :) I have problem with displaying text using DrawText() on StatusBar panel. I wanted to change default text in one of Panels. It works ok but the text have some special characters and they are not displayed properly. What should I do ?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;  Panel: TStatusPanel; const Rect: TRect);var  RectForText: TRect;begin  If (Panel = Statusbar1.Panels[1]) and (StatusBar1.Panels[1].Text<>'') then begin     RectForText := Rect;     StatusBar1.Canvas.Font.Color:=clRed;     StatusBar1.Canvas.Brush.Color:=clDefault;     DrawText(StatusBar.Canvas.Handle, PChar(Panel.Text), -1, RectForText, DT_SINGLELINE or DT_VCENTER or DT_LEFT);  end  else  StatusBar1.Canvas.Font.Color:=clBlack; end; 

jcmontherock:
Which your text and/ or unit encoding ?

TomTom:
I don't know if I understand correctly but I think it is UTF8 .

ASerge:

--- Quote from: TomTom on September 29, 2022, 11:59:59 am ---I don't know if I understand correctly but I think it is UTF8 .

--- End quote ---
This code works great with UTF characters:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;  Panel: TStatusPanel; const Rect: TRect);const  CStyle: TTextStyle = (    Alignment: taLeftJustify;    Layout: tlCenter;    SingleLine: True;    Clipping: True;    ExpandTabs: False;    ShowPrefix: False;    Wordbreak: False;    Opaque: False;    SystemFont: False;    RightToLeft: False;    EndEllipsis: True);begin  if (Panel.Index = 0) and (Panel.Text <> '') then  begin    StatusBar.Canvas.Font.Color := clRed;    StatusBar.Canvas.TextRect(Rect, 0, 0, Panel.Text, CStyle);  end;end;

wp:
Do you have the unit "Windows" in the uses clause? In this case, the ANSI version of the DrawText function in the "Windows" unit is used which expects your string to consist of ANSI characters of your system code page --> the output is wrong. On the other hand, if you have the units "LCLIntf" and "LCLType" in the uses clause (with "Windows" removed, or after "Windows"), the call leads into the win32 widgetset routine which converts the original UTF8 string to a widestring and calls the widestring version of DrawText (DrawTextW) --> the output is correct.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  LCLIntf, LCLType  , Windows              // Comment out Windows, or move it before LCLIntf, and the output will be correct  ; procedure TForm1.FormPaint(Sender: TObject);var  R: TRect;  s: string;begin  R := ClientRect;  s := '間行連知公教物最掲逮山訪襲駆 Λορεμ ιπσθμ δολορ σιτ αμετ';  DrawText(Canvas.Handle, PChar(s), Length(s), R, DT_LEFT);end;

Navigation

[0] Message Index

[#] Next page

Go to full version