|
在lazarus的ODBC连接ansi编码的数据库时,中文总是显示乱码,操作起来的时候都要逐个字段的用ansitoutf8函数转化,很麻烦.
TODBCConnection.LoadField 这个函数应该是lazarus读odbc数据的根儿了,能不能在这里加入编码转换的代码,从而一劳永逸的完成中文问题呢?
case FieldDef.DataType of
{$IF (FPC_VERSION>=2) AND (FPC_RELEASE>=1)}
ftGuid,ftWideString,ftFixedWideChar,
{$ENDIF}
ftFixedChar,ftString: // are mapped to a TStringField (including TGuidField, TWideStringField)
begin
Res:=SQLGetData(ODBCCursor.FSTMTHandle, FieldDef.Index+1, SQL_C_CHAR, buffer, FieldDef.Size, @StrLenOrInd);
//=========================添加代码=============
这段代码写不好,是错误的.大侠们研究研究
tempstr:=ansitoutf8(strpas(buffer));
buffer:=tempstr;
strcopy(buffer,pchar(tempstr));
//==========================结束处理===============
end;
ftSmallint: // mapped to TSmallintField
============================================================
可是我总也写不好这段代码,有高手可以吗? |
|