Handling of Unicode Characters using Delphi 6

后端 未结 2 1918
夕颜
夕颜 2021-01-05 18:34

I have a polling application developed in Delphi 6. It reads a file, parse the file according to specification, performs validation and uploads into database (SQL S

2条回答
  •  孤独总比滥情好
    2021-01-05 18:41

    In non Unicode Delphi version, The basics are that you need to work with WideStrings (Unicode) instead of Strings (Ansi).

    Forget about TADOQuery.SQL (TStrings), and work with TADODataSet.CommandText or TADOCommand.CommandText(WideString) or typecast TADOQuery as TADODataSet. e.g:

    stlTemp: TWideStringList; // <- Unicode strings - TNT or other Unicode lib
    qry: TADOQuery;
    stQuery: WideString; // <- Unicode string
    
    TADODataSet(qry).CommandText := stQuery;
    RowsAffected := qry.ExecSQL;
    

    You can also use TADOConnection.Execute(stQuery) to execute queries directly.


    Be extra careful with Parametrized queries: ADODB.TParameters.ParseSQL is Ansi. If ParamCheck is true (by default) TADOCommand.SetCommandText->AssignCommandText will cause problems if your Query is Unicode (InitParameters is Ansi).

    (note that you can use ADO Command.Parameters directly - using ? chars as placeholder for the parameter instead of Delphi's convention :param_name).


    QuotedStr returns Ansi string. You need a Wide version of this function (TNT)


    Also, As @Arioch 'The mentioned TNT Unicode Controls suite is your best fried for making Delphi Unicode application. It has all the controls and classes you need to successfully manage Unicode tasks in your application.

    In short, you need to think Wide :)

提交回复
热议问题