我是昨天才开始看的delphi,所以问题可能很初级,请见谅是《精通delphi7.0》上的例子程序书中在单元处定义类型,用于处理Unicode字串,
但是我不知道应该怎么放
代码如下:    
TCodePage = (cpThai,
               cpJapan,
               cpChineseSimplified,
               cpKorean,
               cpChineseTraditional,
               cpUnicode,
               cpEastEuropean,
               cpCyrillic,
               cpANSI,
               cpGreek,
               cpTurkish,
               cpHebrew,
               cpArabic,
               cpBaltic,
               cpKoreanJohab);
const CodePageIdentifiers:array[cpThai..cpKoreanJohab] of word
=(874,  //Thai
  932,
  936,
  949,
  950,
  1200,
  1250,
  1251,
  1252,
  1253,
  1254,
  1255,
  1256,
  1257,
  1361
  );
另外附上我打的。pas文件代码(各位如果有时间可以给我看一下不?不胜感激)
unit ChartoUnicode1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }end;
var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var s: string;
i,j,k: integer;
a: array[1..1000] of Char;
begin
s:='';
for i:=1 to Length(Edit1.Text) do begin
j:=Integer (Edit1.Text[i]);
s:=s+Copy(Format('%X',[j+$100]),2,3);
end;Edit2.Text:=s;
StringToWideChar(Edit1.Text,@(a[1]),500);
s:='';
i:=1;
while((a[i]<>#0) or (a[i+1]<>#0)) do begin
j:=Integer(a[i]);
k:=Integer(a[i+1]);
s:=s+Copy(Format('%X',[j*$100+k+$10000]),2,5);
i:=i+2;
end;
Edit3.Text:=s;
end;procedure TForm1.Button2Click(Sender: TObject);
var
ptmp:PWideChar;
wlen:word;
begin
ptmp:=nil;
wlen:=2*Length(Edit1.Text)+2;
ReallocMen(ptmp,wlen);
ZeroMemory(ptmp,wlen);
MultiByteToWideChar(CodePageIdentifiers[cpChineseSimplified],
                    0,
                    PChar(Edit1.Text),
                    Length(Edit1.Text),
                    ptmp,
                    wlen
                    );
Canvas.Font.Color:=clBtnHighlight;
TextOutw(Canvas.Handle,200,200,ptmp,LStrLenW(ptmp));
Canvas.Font.Color:=clBtnShadow;
if ptmp<>nil then begin
FreeMem(ptmp);
ptmp:=nil;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
ptmp:PWidechar;
wlen:word;
begin
ptmp:=nil;
wlen:=2*Length(Edit1.Text)+2;
reallocMem(ptmp,wlen);
ZeroMemory(ptmp,wlen);
StringToWidechar(Edit1.Text,ptmp,wlen);
TextOutW(Canvas.Handle,200,200,ptmp,LStrLenW(ptmp));
Canvas.Font.Color:=clBtnShadow;
Caption:=wideCharToString(ptmp);
if ptmp<>nil then begin
FreeMem(ptmp);
ptmp:=nil;
end;
end;
end.

解决方案 »

  1.   

    unit ChartoUnicode1; interface uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs, StdCtrls; type 
    //放这吧
    {
    TCodePage = (cpThai, 
                  cpJapan, 
                  cpChineseSimplified, 
                  cpKorean, 
                  cpChineseTraditional, 
                  cpUnicode, 
                  cpEastEuropean, 
                  cpCyrillic, 
                  cpANSI, 
                  cpGreek, 
                  cpTurkish, 
                  cpHebrew, 
                  cpArabic, 
                  cpBaltic, 
                  cpKoreanJohab); }
      TForm1 = class(TForm) 
        Label1: TLabel; 
        Label2: TLabel; 
        Label3: TLabel; 
        Edit1: TEdit; 
        Edit2: TEdit; 
        Edit3: TEdit; 
        Button1: TButton; 
        Button2: TButton; 
        Button3: TButton; 
        procedure Button1Click(Sender: TObject); 
        procedure Button2Click(Sender: TObject); 
        procedure Button3Click(Sender: TObject); 
        procedure FormClick(Sender: TObject); 
      private 
        { Private declarations } 
      public 
        { Public declarations } end; 
    //
    {
    const CodePageIdentifiers:array[cpThai..cpKoreanJohab] of word 
    =(874,  //Thai 
      932, 
      936, 
      949, 
      950, 
      1200, 
      1250, 
      1251, 
      1252, 
      1253, 
      1254, 
      1255, 
      1256, 
      1257, 
      1361 
      );
    }
    var 
      Form1: TForm1; 
    可能是这样放的,嘎嘎
      

  2.   

    自己定义的,需要整个文件使用的一般都定义在
    interface 
    uses 
    //使用单元
    type
    // 定义内容
    end; 如果只是某个过程 或函数使用的就直接在
    function /procedure  .... ;
    type
    // 定义内容
    end; 
    var
    //定义变量
    begin
     // 函数、过程体 
    end;