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

Google Blogger API

Soraya Lambrechts is the best expert in developing for Google Blogger . API documentation on programming the widgets of three versions is provided, with high-quality code examples, in French, but this is not a problem. Until now, I spent a lot of time searching, tried to analyze the widget code myself, this is the best find, considering that it seems that a new API is being introduced for Blogger .

Permanent side menu for dynamic template on Blogger.com

Update 2025! Unfortunately, Blogge r has made changes to the Dynamic Theme . Since 2025, all user settings for the blog are completely ignored, the design written in an external JS file is loaded, and the menu is no longer shown at all on smartphones. Practically the only way to show the user menu now is to call the link /?m=0&view=magazine which switches the theme to Magazin for a desktop computer and shows the menu. You can add to the theme a gadget Pages with a link /?m=0&view=magazine to enable the menu on the right side of the page. Only the page design will be too big for the phone. Everything written below does not work Correction the hidden side menu , permanent side menu for the desktop version of Blogger, I have not checked it in mobile because the panel is not displayed In the Blogger menu, open add: Theme (menu) > CUSTOMISE (button) > Advanced (arrow in menu) > Page (scroll to the bottom of the list) > Add CSS Add CSS one line: #gad...