Page 1 of 1

UseUnicode option not work in Lazarus

Posted: Thu 12 Dec 2013 12:24
by dionic
Hello people. Sorry for my bad english. I have some question or problem.
I use Linux(Ubuntu 13.04), PostgreSQL 9.2, Lazarus 1.0.12 and Unidac components 4.1.

I have some project without gui. Just console mode. When i build it with using module Interfaces and LCL all work fine and i see russian character. But if i build my application without that modules russian character displayed "?" .

Part of my simple test code:

Code: Select all

program appdaemon;

{$mode objfpc}{$H+}
{$DEFINE UNIX}
{$DEFINE UseCThreads}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  SysUtils,
  CustApp,
  apFuncs,
  SYNCOBJS,
  appManager,
  dmServDBSimple,
//Interfaces,
  enVarUtils,
  other_funcs,
  unidac10,
  AnyClases,
  variants,
  baseunix,
  libc,
  enSessionStore,
  erIniSettings,
  erSQLClasses,
  db;             

...


var
  lConnect: TerSQLConnection;
  lQuery: TerSQLQuery;
  lstr,lq: String;
  i: Integer;
begin
  try

    Writeln('Start connecting to database...');

    try
      lConnect:= TerSQLConnection.Create(nil);
      lQuery:= TerSQLQuery.Create(nil);

      with lConnect do begin
        Server  := '192.168.1.202';
        Database:= 'kbtm';
        Username:= 'energy_dba';
        Password:= 'dev_pass';
        ProviderName:= 'postgresql';
        SpecificOptions.Values['PostgreSQL.UseUnicode']:= 'True';
      end;
      lConnect.Connected:= True;

      Writeln('Connecting to database is DONE');

      Writeln('Select data from SREZ...');

      lq:= 'select * from srez_type';

      lQuery.Connection:= lConnect;
      lQuery.SpecificOptions.Values['ExtendedFieldsInfo']:= 'true';

      with lQuery do begin
        SQL.Clear;
        SQL.Add(lq);
        Open;
      end;

      Writeln('Select data from SREZ is DONE. Recordscount - ' + IntToStr(lQuery.RecordCount));

      lQuery.First;
      while not lQuery.EOF do begin
        lstr:= 'TYPE = ' + lQuery.FieldByName('IDNAME').AsWideString;
        Writeln('str:' + lstr);

        Writeln('str1:' + Utf8ToAnsi(UTF8Encode(lstr)));

        lQuery.Next;
      end;

    except
      on E: Exception do begin
        Writeln('Error:' + e.Message);
      end;
    end;

  finally
    FreeAndNil(lQuery);
    FreeAndNil(lConnect);
  end;  

Please answer the question why this is happening? What am I doing wrong?

P.S.
And another point. If i don't use this option ("UseUnicode") i receive clipped data but in right charset. Example: if charecter varying field length is 20 and length of the data in this field is 15 character then i see only 10 character.

Re: UseUnicode option not work in Lazarus

Posted: Fri 13 Dec 2013 08:40
by AlexP
Hello,

To work correctly with Unicode characters, you should add the cwstring unit. More detailed info can be found in the FPC documentation: http://wiki.freepascal.org/Console_Mode ... .29_output

Re: UseUnicode option not work in Lazarus

Posted: Fri 13 Dec 2013 09:18
by dionic
Thanks Alex. Everything worked!

Re: UseUnicode option not work in Lazarus

Posted: Fri 13 Dec 2013 10:04
by AlexP
Hello,

Glad to see that the problem was solved. If you have any other questions, feel free to contact us.