Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 6340|回复: 4

KOL常用数据转换方法

[复制链接]

该用户从未签到

发表于 2009-6-18 13:13:18 | 显示全部楼层 |阅读模式
KOL常用数据转换方法



(1)整数与字符数据转换
procedure TForm1.Button1Click(Sender: PObj);
var//数据类型说明
aa,cc:integer;//整数aa
bb:string;//字符型bb
begin
aa:=111;
bb:='222';
label1.caption:=int2str(aa);//把整数转为字符串
cc:=aa+str2int(bb);//str2int(bb)把字符转为整数
label1.caption:=int2str(cc);
end;

(2)时间转换为字符串
procedure TForm1.Timer1Timer(Sender: PObj);
begin
Label1.Caption :=Time2StrFmt('hh:mm:ss',now);//包括显示“秒”
end;

(3)日期时间转换为字符串
procedure TForm1.Timer1Timer(Sender: PObj);
begin
Label1.Caption := DateTime2StrShort(now);
end;

(4)字符串转为日期时间
procedure TForm1.Button1Click(Sender: PObj);
var
aa:string;
begin
aa:='2002-10-18';
label2.Caption:=DateTime2StrShort(Str2DateTimeShort(aa));
//DateTime2StrShort(now) 日期时间转字符
//Str2DateTimeShort(aa); 字符转为日期时间
end;


(5)日期转换为字符串
procedure TForm1.Timer1Timer(Sender: PObj);
begin
Label1.Caption :=Date2StrFmt('yyyy-MM-dd',now);
//now为现在时间
end;


(6)整数转为十六进制

procedure TForm1.Button1Click(Sender: PObj);
var
aa:integer;
bb:string;
begin
aa:=49;
bb:=int2hex(aa,aa);//整数49转换后变为十六进制的31
label1.Caption:=bb;
end;


(7)十六进制转为整数
procedure TForm1.Button1Click(Sender: PObj);
var
aa:integer;
bb:string;
begin
bb:='31';
aa:=hex2int(bb);//十六进制的31转换后变为整数49
label1.Caption:=int2str(aa);
end;

评分

参与人数 1威望 +5 收起 理由
猫工 + 5 原创内容

查看全部评分

回复

使用道具 举报

该用户从未签到

发表于 2009-7-22 06:38:56 | 显示全部楼层
学习谢谢!
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2009-9-10 17:12:28 | 显示全部楼层
1KOL 常用函数函数
  2kol.pas
  3//绝对值函数
  4function Abs( X: Integer ): Integer;
  5//64位加法
  6function Add64( const X, Y: I64 ): I64;
  7//内存分配函数
  8function AllocMem( Size : Integer ) : Pointer;
  9//Ansi字符串比较
10function AnsiCompareStr(const S1, S2: KOLString): Integer;
11//不区分大小写Ansi字符串比较
12function AnsiCompareStrNoCase(const S1, S2: KOLString): Integer;
13//比较文本
14function AnsiCompareText( const S1, S2: AnsiString ): Integer;
15// 比较Ansi字符串是否相等
16function AnsiEq( const S1, S2 : AnsiString ) : Boolean;
17//转换字符串为小写
18function AnsiLowerCase(const S: Ansistring): Ansistring;
19//转换字符串为大写
20function AnsiUpperCase(const S: Ansistring): Ansistring;
21//二进制转换为十进制
22function Binary2Int( const Value: AnsiString ) : Integer;
23//十六进制转十进制
24function cHex2Int( const Value : AnsiString) : Integer;
25//TColor转换为Color15
26function Color2Color15( Color: TColor ): WORD;
27// TColor转换为Color16
28function Color2Color16( Color: TColor ): WORD;
29// Color转RGB
30function Color2RGB( Color: TColor ): TColor;
31//混合两种Tcolor颜色
32function ColorsMix( Color1, Color2: TColor ): TColor;
33//截取字符串尾部的Len长度的字符串
34function CopyTail( const S : KOLString; Len : Integer ) : KOLString;
35//获取当前日期
36function Date: TDateTime;
37//格式化的日期格式
38function Date2StrFmt( const Fmt: KOLString; D: TDateTime ): KOLString;
39//日期时间,短格式
40function DateTime2StrShort( D: TDateTime ): AnsiString;
41//返回是一周的第几天
42function DayOfWeek(Date: TDateTime): Integer;
43// Double转Int64
44function Double2Int64( D: Double ): I64;
45// Double转Str
46function Double2Str( D: Double ): AnsiString;
47// Extended转Str
48function Extended2Str( E: Extended ): AnsiString;
49// Format函数
50function Format( const fmt: KOLString; params: Array of const ): KOLString;
51//取得文件夹下面的文件,返回StrList列表
52function GetFileList(const dir: Ansistring): PStrList;
53//取得文件夹下面的文件,Fmask指定要取得的扩展名,返回StrList列表
54function GetFileListStr(FPath{e.g.'c:\\tmp\\'}, FMask{e.g.'*.*'}: KOLString): KOLString;
55//得到临时文件夹的位置
56function GetTempDir : KOLString;
57//取得桌面工作区大小
58function GetWorkArea: TRect;
59// Hex转Int
60function Hex2Int( const Value : AnsiString) : Integer;
61//十进制转二进制
62function Int2Digs( Value, Digits : Integer ) : AnsiString;
63//十进制转十六进制
64function Int2Hex( Value : DWord; Digits : Integer ) : AnsiString;
65// Int扩展成Int64
66function Int2Int64( X: Integer ): I64;
67// Int转PChar
68procedure Int2PChar( s: PAnsiChar; Value: Integer );
69// 十进制转罗马字符
70function Int2Rome( Value: Integer ): AnsiString;
71//十进制转字符串
72function Int2Str( Value : Integer ) : AnsiString;
73//十进制转字符串
74function Int2StrEx( Value, MinWidth: Integer ): AnsiString;
75// Int64转Double
76function Int64_2Double( const X: I64 ): Double;
77//Int64转十六进制
78function Int64_2Hex( X: I64; MinDigits: Integer ): AnsiString;
79//Int64转str
80function Int64_2Str( X: I64 ): AnsiString;
81//构造Int64
82function MakeInt64( Lo, Hi: DWORD ): I64;
83//构造一个Point
84function MakePoint( X, Y: Integer ): TPoint;
85//构造Rect
86function MakeRect( Left, Top, Right, Bottom: Integer ): TRect; stdcall;
87// 构造SmallPoint
88function MakeSmallPoint( X, Y: Integer ): TSmallPoint;
89//Max函数
90function Max( X, Y: Integer ): Integer;
91//Min函数
92function Min( X, Y: Integer ): Integer;
93//对话框MsgBox函数
94function MsgBox( const S: KOLString; Flags: DWORD ): DWORD;
95// MsgOK对话框函数
96procedure MsgOK( const S: KOLString );
97//AnsiChar转Int
98function S2Int( S: PAnsiChar ): Integer;
99//对话框ShowMessage函数
100procedure ShowMessage( const S: KOLString );
101//对话框ShowMessage函数
102function ShowMsg( const S: KOLString; Flags: DWORD ): DWORD;
103// Str转DateTimeFmt函数
104function Str2DateTimeFmt( const sFmtStr, sS: KOLString ): TDateTime;
105// Str转DateTime
106function Str2DateTimeShort( const S: KOLString ): TDateTime;
107// Str转Double
108function Str2Double( const S: AnsiString ): Double;
109// Str转Extended
110function Str2Extended( const S: AnsiString ): Extended;
111// Str保存到File
112function Str2File( Filename: PKOLChar; Str: PAnsiChar ): Boolean;
113// Str转Int
114function Str2Int(const Value : AnsiString) : Integer;
115// Str转Int64
116function Str2Int64( const S: AnsiString ): I64;
117// StrCat
118function StrCat( Dest, Source: PAnsiChar ): PAnsiChar;
119// StrComp
120function StrComp(const Str1, Str2: PAnsiChar): Integer; assembler;
121// StrComp_NoCase不区分大小写
122function StrComp_NoCase(const Str1, Str2: PAnsiChar): Integer;
123//字符串复制
124function StrCopy( Dest, Source: PAnsiChar ): PAnsiChar; assembler;
125//字符串相等比较
126function StrEq( const S1, S2 : AnsiString ) : Boolean;
127//返回字符串长度
128function StrLen(const Str: PAnsiChar): Cardinal; assembler;
129//Pchar复制
130function StrPCopy(Dest: PAnsiChar; const Source: Ansistring): PAnsiChar;
131// StrReplace字符串替换函数
132function StrReplace( var S: AnsiString; const From, ReplTo: AnsiString ): Boolean;
133//系统时间转字符串函数
134function SystemTime2Str( const SystemTime : TSystemTime; const LocaleID : DWORD;                         const Flags : TTimeFormatFlags; const TimeFormat : PKOLChar ) : KOLString;
135//文本复制到剪贴板
136function Text2Clipboard( const S: AnsiString ): Boolean;
137//时间转字符串
138function Time2StrFmt( const Fmt: KOLString; D: TDateTime ): KOLString;
139//字符串去除空格函数
140function Trim( const S : KOLString): KOLString;
141//转换大写
142function UpperCase(const S: Ansistring): Ansistring;
143// UTF8转WideString
144function UTF8_2WideString( const s: AnsiString ): WideString;
145
146mirror.pas
147//Bool转Str
148function Bool2Str( const S: String ): String;
149//TColor转Str
150function Color2Str( Color: TColor ): String;

"www.cnblogs.com/sun_catboy/archive/2008/10/17/1313753.html"
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2009-9-12 17:50:37 | 显示全部楼层
引用第1楼myid于2009-07-22 06:38发表的  :
学习谢谢!
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2009-9-12 17:50:56 | 显示全部楼层
引用第2楼sun_catboy于2009-09-10 17:12发表的  :
  1KOL 常用函数函数
  2kol.pas
  3//绝对值函数
  4function Abs( X: Integer ): Integer;
  5//64位加法
.......
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 22:36 , Processed in 0.035426 second(s), 14 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表