我是昨天才开始看的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.
但是我不知道应该怎么放
代码如下:
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.
解决方案 »
- 如何获取其他进程中MSFlexGrid的内容-该MSFlexGrid的句柄已经取得
- fillchar效率竟然不高
- 什么时候用B/S,什么时候用C/S?
- 请问一个报表问题,十分着急,客户在等待答复~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- DBGrid数据显示和打印问题~~~~
- DBCheckBox有3种状态?
- 如何检测某个字段是什么类型的?此字段为用户所建。
- 如何把txt文件以ascii方式读取,另何处可以下载vb帮助文件
- 采用C++Builder6(Delphi6)与采用VS.Net开发B/S结构的应用哪个更好?各自有什么特点?希望大家都谈谈看法。
- 请问怎么修改button的颜色和形状呢???
- 如何得到共享文件的本地位置
- delphi 调用配置了SSL的C#开发的WebServices时.
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;
可能是这样放的,嘎嘎
interface
uses
//使用单元
type
// 定义内容
end; 如果只是某个过程 或函数使用的就直接在
function /procedure .... ;
type
// 定义内容
end;
var
//定义变量
begin
// 函数、过程体
end;