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)
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
Post a Comment