function TForm1.unlegalXMLcharactor(const s: WideChar):Boolean; //非法字符
begin
Result := False;
if not((s = #$9) or (s = #$A)
or (s = #$D)
or ((s > #$1F) and (s < #$D800))
or ((s > #$DFFF) and (s < #$FFFE))
or ((s > #$FFFF) and (s <= #$10FFFF))) then Result :=True ;
end;procedure TForm1.Button1Click(Sender: TObject);
var
ms: TMemoryStream;
savems: TMemoryStream;
current: WideChar;
change: Boolean;
memint: integer;
pc,ps: PChar;
begin
change := False;
memint :=0;
if OpenDialog1.Execute then
begin
ms := TMemoryStream.Create; //输入流
savems := TMemoryStream.Create; //输出流
ms.LoadFromFile(OpenDialog1.FileName);
savems.SetSize(ms.Size); //初始化输出流长度
pc := ms.Memory;
ps := savems.Memory;
ms.Position :=0;
savems.Position :=0;
解决方案 »
- 求一个简单的C函数的DELPHI翻译
- 哪个品牌的视频监控卡(4路以上)带有delphi的例子或者sdk
- 如何让printdbgrideh预览窗口始终显示在最前面
- 求如何制作delphi控件,可以嵌入网页中使用的!!!
- MIDAS稳定性
- 怎样用DELPHI编写手机短信炸弹?
- 《Delphi7高效率数据库程序设计》附书光盘中找不到D7Books.GDB文件???
- 为什么我的QReport里,Custom size在定义纸张大小时,一超过2540就说VALUE TOO BIG!
- 如何制作DELPHI应用程序的发布盘?
- 紧急问题!!!GIS高手请进)
- 获得当前系统分区,并写入文件,但是只能写入U盘,请问怎么回事?
- d7+qreport打印临时表,只显示一条记录
begin
ms.Read(current,2); //宽字符读取
// ShowMessage(current); if unlegalXMLcharactor(current) then
begin
if change = False then
begin
if (MessageDlg('文件中有非法字符,是否需求转换?',mtWarning,mbOKCancel,0)= mrOk) then change := True
end;
// ShowMessage(IntToStr(ms.Position));
Continue;
end
else
begin
ps[memint] := pc[ms.position-2];
ps[memint+1] := pc[ms.position-1];
memint := memint +2;
end;
end;
savems.SetSize(memint);
// ShowMessage(IntToStr(ms.Position));
if change = True then
begin
savedialog1.filename := OpenDialog1.FileName;
SaveDialog1.InitialDir := ExtractFilePath(ParamStr(0));
if SaveDialog1.Execute then
begin
if extractfileExt(savedialog1.FileName)<>'.nqd' then
SaveDialog1.FileName := ChangeFileExt(SaveDialog1.FileName,'.nqd');
savems.SaveToFile(SaveDialog1.FileName);
end;
end;
change := False;
savems.Free;
ms.Free;
end;
end;
end.
当运行时,总是在半路出现runtime error at 216 错误,确实不知道哪里出现了问题,寻求帮助(DELPHI2009),但是在delphi7下完全正常