环境D2009移植D7的小票打印程序,D7中一切正常
D2009中直接打印出乱码,不知是何情况。上程序uses
...Printers;
.
.
.
procedure TForm1.Button1Click(Sender: TObject);
var
F_file:TextFile;
begin
with Printer do
begin AssignPRN(f_file);
Rewrite(f_file); Canvas.Font.Name:= '黑体';
Canvas.Font.Size:=15;
Canvas.Font.Style:=[fsBold];
Writeln(f_file,'测试文字');
Writeln(f_file,''); CloseFile(f_file); end;//with
end;
D2009中直接打印出乱码,不知是何情况。上程序uses
...Printers;
.
.
.
procedure TForm1.Button1Click(Sender: TObject);
var
F_file:TextFile;
begin
with Printer do
begin AssignPRN(f_file);
Rewrite(f_file); Canvas.Font.Name:= '黑体';
Canvas.Font.Size:=15;
Canvas.Font.Style:=[fsBold];
Writeln(f_file,'测试文字');
Writeln(f_file,''); CloseFile(f_file); end;//with
end;
解决方案 »
- INDY 10编译不了..
- 小小问题,麻烦大家看看!
- MIDAS中的Socket:急,在线
- 怎样编写服务器端用SQL的C/S程序?用何种方式连接数据库最好?谢谢!!!
- 录入词典的问题
- 我公司开发的软件著作权被别人申请了!太气愤了,程序员都是弱势群体吗?我就不信随便谁都能欺负
- 高手请进,关于线程的问题,如能解决问题奉送800分
- Delphi XE5调用Tomcat SOAP出错,请各路上仙不吝赐教....
- [TIPS]在不同的窗口打开一个URL的最简单的方法!
- 好消息:从网上找到李维的《Delphi 5.X分布式多层应用电子商务篇》了
- for..in..do 的问题
- 求AdvStringGrid控件
var
F_file:TextFile;
s:AnsiString;
begin
s:='测试文字';
with Printer do
begin AssignPRN(f_file);
Rewrite(f_file); Canvas.Font.Name:= '黑体';
Canvas.Font.Size:=15;
Canvas.Font.Style:=[fsBold];
Writeln(f_file,s);
//Writeln(f_file,''); CloseFile(f_file); end;//with
end;
用这种方法无论要不要
Canvas.Font.Name:= '黑体';
Canvas.Font.Size:=15;
Canvas.Font.Style:=[fsBold];
打印出来的均是乱码
Writeln(f_file,s); 我也感觉是字符集的问题,但不知道怎么处理。
但printer比較特殊,這樣處理:
{ Called when a Write or Writeln is applied to a printer file. The calls
PrnString to write the text in the buffer to the printer. }
function PrnOutput(var F: TTextRec): Integer;
begin
with F do
begin
PrnString(PrnRec(UserData), PAnsiChar(BufPtr), BufPos);
BufPos := 0;
Result := 0;
end;
end;所以應先聲明一個ansiString類型的變量,來接收字串。或直接強制轉換PANsichar
用PANsichar()强转我当时就试过了,仍然不成