关于PaxCompiler字符串注意的问题

来源:互联网 发布:床垫哪个品牌好 知乎 编辑:程序博客网 时间:2024/05/27 06:16
 继续我的PaxCompiler游戏脚本创作,发现个问题,在PaxCompiler脚本里面定义一个类(不是主脚本),主脚本引用这个定义类的脚本,返回一个字符串, 这个字符串显示出来是乱码, 如果再主脚本里面定义,对话框显示出来就不是乱码,调试发现,PaxCompiler保存字符串为UTF8的模式,显示的时候调用UTF8ToString函数转换下显示:

unit Unit1;interfaceuses  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, PaxRunner,  PaxInterpreter, PaxCompiler, FMX.Controls.Presentation, FMX.StdCtrls;type  TForm1 = class(TForm)    PaxCompiler1: TPaxCompiler;    PaxPascalLanguage1: TPaxPascalLanguage;    PaxInterpreter1: TPaxInterpreter;    Button1: TButton;    Button2: TButton;    PaxInterpreter2: TPaxInterpreter;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;{ TGameLogin }var  Form1: TForm1; // TPersistentClassimplementation{$R *.fmx}uses PaxRegister ; procedure Msg(AsText:String) ; var  List:TStrings ; begin   List:=TStringList.Create ;   try   List.Text:=AsText ;   List.SaveToFile('1.txt');   finally   List.Free ;   end;   ShowMessage(UTF8ToString(AsText)); end;procedure TForm1.Button1Click(Sender: TObject);var i:Integer ;begin  PaxCompiler1.Reset;  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);  PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName);  PaxCompiler1.AddCodeFromFile('1','test.pas');  if PaxCompiler1.Compile(PaxInterpreter1, False, False) then  begin   PaxInterpreter1.Run ;   PaxInterpreter1.SaveToFile('test.bin');  end  else  begin   for I:=0 to PaxCompiler1.ErrorCount - 1 do      ShowMessage(PaxCompiler1.ErrorMessage[I]);  end;end;procedure TForm1.Button2Click(Sender: TObject);begin  PaxInterpreter2.Resume ;  PaxInterpreter2.LoadFromFile('test.bin');  PaxInterpreter2.Run ;end;procedure TForm1.FormCreate(Sender: TObject);begin  RegisterTypeAlias(0,'LChar',_typeWIDESTRING);  RegisterHeader(0,'procedure Msg(AsText:string) ;',@Msg) ;end;end.

脚本

uses GameLogin ;var Login:TGameLogin ; begin  Login:=TGameLogin.Create ;  Login.Show('delphi我最喜欢的编程语言...') ; end.

unit GameLogin;interface{ TGameLogin }type  TGameLogin = class(TObject)  private  protected  public    procedure Show(AsText:string);    constructor Create;    destructor Destroy; override;  published  end;implementation{ TGameLogin }constructor TGameLogin.Create;begin inherited ;end;destructor TGameLogin.Destroy;begin  inherited;end;procedure TGameLogin.Show(AsText:string) ;begin Msg(AsText) ; end ;end.


原创粉丝点击