使用Lazarus不得不面对编码问题,尤其中文。Lazarus使用的是UTF8编码,而很多windows程序使用的是ANSI编码,编码问题在此不多说大家可以google去。
ANSI数据库与Lazarus编程的解决方法:
1.全局设置一个isNeedANSI变量;
2.从数据库读取时:
function Tdmd.FromDBStr(str:string):string;
begin
if IsNeedANSI then result:= ANSItoUTF8(str)
else result:=str;
end;
3.向数据库写入数据时:
function Tdmd.ToDBStr(dbstr:string):string;
begin
if IsNeedANSI then result:= UTF8toANSI(dbstr)
else result:=dbstr;
end;
4.TDBGrid的修改:
修改Grid文件里的TcustumerGrid类,添加一个非publish变量
ConverType
修改如下过程:
procedure TCustomGrid.DrawCellText(aCol, aRow: Integer; aRect:
TRect;
aState: TGridDrawState; aText: String);
begin
with ARect do begin
dec(Right, 3);
case
Canvas.TextStyle.Alig