Skip to main content

SynEdit project TDBSynEdit fix for unicode memo fields

SynEdit is a syntax highlighting edit control for  Delphi and Kylix

Symptom

 Component TDBSynEdit cannot open the BLOB field of SQLite3 database if the data type is set to TEXT and UTF8 encoding. Zeos unicode v7.2.6 components (UTF16) are used to access database SQLite3. 
Source code SynDBEdit.pas (2014-10-13)

Solution

 Replace LoadMemo default encoder type Byte to Unicode 2 bytes, if data field type is Widestring. The code below tested in Delphi XE6 and 10.1
 
procedure TCustomDBSynEdit.LoadMemo;
{$IFDEF UNICODE}
const
 BlobFieldWideText = [ftWideMemo,ftWideString];
{$ENDIF}
{$IFDEF SYN_COMPILER_3_UP}
var
  BlobStream: TStream;
{$ELSE}
var
  BlobStream: TBlobStream;
  BlobField: TBlobField;
{$ENDIF}
begin
  try
{$IFDEF SYN_COMPILER_3_UP}
    BlobStream := FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmRead);
{$ELSE}
    BlobField := FDataLink.Field as TBlobField;
    BlobStream := TBlobStream.Create(BlobField, bmRead);
{$ENDIF}
    Lines.BeginUpdate;
{$IFDEF UNICODE}
//03.12.2019 iThyx_AK° fix for unicode
//Tested on UTF8 TEXT Sqlite3 & Zeos Unicode (UTF16) v7.2.6
//For UTF8 use: System.SysUtils.TEncoding.UTF8
    if (FDataLink.Field is  TBlobField) and
 (TBlobField(FDataLink.Field).BlobType in BlobFieldWideText) then
      Lines.LoadFromStream(BlobStream, TEncoding.Unicode)
    else Lines.LoadFromStream(BlobStream, TEncoding.Default);
{$ELSE} //Non Unicode
    Lines.LoadFromStream(BlobStream);
{$ENDIF}
    Lines.EndUpdate;
    BlobStream.Free;
    Modified := False;
    ClearUndo;
  except
    // Memo too large
    on E: EInvalidOperation do
      Lines.Text := Format('(%s)', [E.Message]);
  end;
  EditingChange(Self);
end;
 
 
 

Comments

Popular posts from this blog

To GitHub Support - I do not understand why blocked my account

 It's only been 3 months and GitHub blocked my account, for no good reason. Github service does not stand up to any criticism-there is no longer a desire to use it and I delete the account. Прошло всего 3 месяца и GitHub заблокировал мой аккаунт, без всякой достойной внимания причины. Сервис GitHub не выдерживает никакой критики - больше нет желания им пользоваться и аккаунт я удаляю. UPDATE: Sam (GitHub Developer Support) Hi Andy, Thanks for reaching out, and apologies for any frustration with our password requirements. Unfortunately, that message indicates your current password (or more specifically, a hash of that password) has been found in an internal database of credentials known to be compromised by breaches of other websites or services.   To be clear, your password being exposed does not relate to any data breach of GitHub.com but, due to its presence in that database, it should be considered significantly less secure and changed immediately.» Ps. I do not