为什么生成dbf文件英文表头就没事,中文表头就是乱码而且出错呢?(100分)

W

wd5i

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; TempStr1,TempStr2,Msg:string;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; with Fdm.Table1 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Active:=False;<br>&nbsp; &nbsp; &nbsp; &nbsp; TableName:='a.dbf';<br>&nbsp; &nbsp; &nbsp; &nbsp; TableType:=ttFoxPro;<br>&nbsp; &nbsp; &nbsp; &nbsp; FieldDefs.Add('第一列',ftstring,30);//FieldDefs.Add('A',ftString,30);//这里写成英文就没问题,中文就是乱码 &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; FieldDefs.Add('第二列',ftstring,30);//FieldDefs.Add('B',ftString,30);<br>&nbsp; &nbsp; &nbsp; &nbsp; FieldDefs.Add('第三列',ftstring,30);//FieldDefs.Add('C',ftstring,30);<br>&nbsp; &nbsp; &nbsp; &nbsp; CreateTable;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; except<br>&nbsp; &nbsp; MessageDlg('出现异常,无法创建dbf文件!',mtInformation,[mbOk],0);<br>&nbsp; end;<br><br>&nbsp; TempStr1:='为啥表头写中文就出错呢?'; TempStr2:='Demo2';<br><br>&nbsp; try<br>&nbsp; &nbsp; with Fdm.Query1 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; SQL.Add('insert into a(第一列,第二列) values('+''''+TempStr1+''''+','+''''+TempStr2+''''+') ');<br>&nbsp; &nbsp; &nbsp; //SQL.Add('insert into a(A,B) values('+''''+TempStr1+''''+','+''''+TempStr2+''''+')');//换成英文就没问题<br>&nbsp; &nbsp; &nbsp; &nbsp; ExecSQL;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; Msg:='Dbf文件生成完毕,文件保存在'+ExtractFilePath(Application.ExeName)+'下!';<br>&nbsp; &nbsp; MessageDlg(Msg,mtInformation,[MbOk],0);<br>&nbsp; except<br>&nbsp; &nbsp; MessageDlg('出现异常,向dbf文件中插入数据出错!',mtInformation,[MbOk],0);<br>&nbsp; end;<br>end;
 
表名和字段名尽量不要用中文<br>为节约时间,最好不要去试图解决这个问题,使用英文表名和字段名就可以了
 
我也不想用中文啊,可是要的就是中文字段的dbf文件,要和别的程序接口用。我也不想浪费时间的。
 
大家来帮帮忙啊
 
FieldDefs.Add('第一列',ftstring,30);//FieldDefs.Add('A',ftString,30);//这里写成英文就没问题,中文就是乱码 &nbsp; &nbsp; &nbsp; <br>其中的'第一列'你用《微软拼音输入法3.0版》输入试试
 
这和输入法没关系吧
 
Up一下,没人知道吗?或者不用BDE,用ADO生成DBF文件也行
 
顶部