#1 2023-06-05 16:33:47

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

TOrmTableToGrid Hints display wrongly encoded chars

In MS Windows 10, a win32 mormot app compiled with Delphi XE. The following displays the contents of a TOrm class (TStatus) in a DrawGrid, using the TOrmTabletoGrid class (table is a local TOrmTable variable):

  if ConnectToServer then
  begin
    status := TStatus.CreateAndFillPrepare(Client.Orm, '');
    try
      table := status.FillTable;
      table.OwnerMustFree := false;
      OrmTableToGrid := TOrmTableToGrid.Create(DrawGrid1, status.FillTable, Client);
      OrmTableToGrid.OnHintText := OnHintText;
    finally
      status.Free
    end
  end

ctrl-click displays hint strings polluted with erroneous characters, like Chinese, rectangles etc. However the debug of OnHintText event handler shows that the Text output variable contains the correct string values:

function TMainForm.OnHintText(Sender: TOrmTable; FieldIndex, RowIndex: Integer;
  var Text: string): boolean;
begin
  Text := (Sender as TOrmTable).GetString(RowIndex,FieldIndex);
  Result := true
end;

Any help is welcome.

Offline

#2 2023-06-06 21:06:56

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: TOrmTableToGrid Hints display wrongly encoded chars

I found the problem's cause in mormot.ui.core unit, in procedure DrawTextUtf8. Utf8DecodeToUnicode doesn't seem to work properly. Below is the modified version which works in my system (the original code is commented out):

procedure DrawTextUtf8(Control: TCustomControl; Canvas: TCanvas;
  const Text: RawUtf8; var Rect: TRect; CalcOnly: boolean);
var
//  tmp: TSynTempBuffer;
  s: string;
begin
//  Utf8DecodeToUnicode(Text, tmp);
  s := Utf8ToString(Text);
  DrawText(Canvas.Handle, PWideChar(s), length(s), Rect,
    DrawTextFlags(Control, CalcOnly));
//  DrawText(Canvas.Handle, tmp.buf, tmp.len shr 1, Rect,
//    DrawTextFlags(Control, CalcOnly));
//  tmp.Done;
end;

Offline

#3 2023-06-07 06:18:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TOrmTableToGrid Hints display wrongly encoded chars

You are right.

It should be fixed by https://github.com/synopse/mORMot2/commit/57c91dab
The UTF-16 buffer length was incorrect, so too many random chars were displayed.

I am sorry for the bug, but the UI part of mORMot 2 is less tested than the non-UI/server part, because we mostly use it for server work yet.
And it is almost impossible to unit-test some UI code.
These UI units were directly converted from mORMot 1, and certainly some bugs did appear within the conversion.
Don't hesitate to come back here and report any problem.

Thanks a lot for having taken the time to debug and find the root cause.

Offline

#4 2023-06-08 06:13:29

damiand
Member
From: Greece
Registered: 2018-09-21
Posts: 94

Re: TOrmTableToGrid Hints display wrongly encoded chars

You're welcome, thank you @ab (and the rest of the mormot contributors) for your outstanding work! smile

Offline

Board footer

Powered by FluxBB