Showing posts with label Pascal. Show all posts
Showing posts with label Pascal. Show all posts

Mar 7, 2009

【转】Delphi中常用VCL函数说明

BCB/Delphi中常用的VCL函数说明
说明,BCB,Delphi,C++Builder,内存分配,文件操作,磁盘目录管理,字符串操作,时间日期管理,类型转换

--------------------
内存分配
--------------------
函数名称:AllocMem
函数说明:在队中分配指定字节的内存块,并将分配的每一个字节初始化为 0.函数原型如下:
void * __fastcall AllocMem(Cardinal Size);

函数名称:SysFreeMem
函数说明:释放所指定的内存块.函数原型如下:
int __fastcall SysFreeMem(void * P);

函数名称:SysReallocMem
函数说明:要求重新分配参数Size所指定的内存.函数原型如下:
void * __fastcall SysReallocMem(void * P , int Size);

--------------------
文件操作
--------------------
函数名称:ChangeFileExt
函数说明:更改指定文件的扩展名,函数原型如下:
AnsiString __fastcall ChangeFileExt(const AnsiString FileName,const AnsiString Extension);

函数名称:DeleteFile
函数说明:在计算机磁盘中删除指定的文件,如果操作成功,则函数返回真,函数原型如下:
bool __fastcall DeleteFile(const AnsiString FileName);

函数名称:ExtractFileDir
函数说明:返回指定文件的工作目录,函数原型如下:
AnsiString __fastcall ExtractFileDir(const AnsiString FileName);

函数名称:ExtractFileDrive
函数说明:返回指定文件的驱动器,函数原型如下:
AnsiString __fastcall ExtractFileDrive(const AnsiString FileName);

函数名称:ExtractFileExt
函数说明:返回指定文件的扩展名,函数原型如下:
AnsiString __fastcall ExtractFileExt(const AnsiString FileName);

函数名称:ExtractFileName
函数说明:返回指定文件的文件名及扩展名,函数原型如下:
AnsiString __fastcall ExtractFileName(const AnsiString FileName);

函数名称:ExtractFilePath
函数说明:返回指定文件的工作路径,函数原型如下:
AnsiString __fastcall ExtractFilePath(const AnsiString FileName);

函数名称:FileAge
函数说明:返回指定文件的时间标签,如果操作失败,则返回-1,函数原型如下:
int __fastcall FileAge(const System::AnsiString FileName);

函数名称:FileClose
函数说明:关闭指定的文件,函数原型如下:
void __fastcall FileClose(int Handle);

函数名称:FileCreate
函数说明:以指定的文件名称创建一个新的文件,如果返回为正数,表示操作成功,返回值为文件句柄,如果返回值为-1,表示操作失败.函数原型如下:
int __fastcall FileCreate(const System ::AnsiString FileName);

函数名称:FileExists
函数说明:用于测试指定的文件是否存在,如果存在返回真,否则返回假,函数原型如下:
bool __fastcall FileExists(const System::AnsiString FileName);

函数名称:FileGetAttr
函数说明:返回指定文件的属性,如果操作失败,则函数返回-1,函数原型如下;
int __fastcall FileGetAttr(const System::AnsiString FileName);

函数名称:FileGetDate
函数说明:返回指定文件的DOS时间标签,如果操作失败,则近回-1,函数原型如下:
int __fastcall FileGetDate(int Handle);

函数名称:FileOpen
函数说明:打开指定的文件,如果返回为正数,表示操作成功,返回值为文件句柄:如果返回值为-1,表示操作失败,函数原型如下:
int __fastcall FileOpen(const System::AnsiString FileName,int Mode);

函数名称:FileRead
函数说明:从文件中读取指定字节的数据到缓冲区中,函数返回实际读取的字节数,函数原型如下;
int __fastcall FileRead(int Handle,void *Buffer,int Count);

函数名称:FileSeek
函数说明:调整文件指针到新的位置,如果操作成功,则返回新的文件位置,如果操作失败,则函数返回-1,函数原型如下:
int __fastcall FileSeek(int Handle,int Offset,int Origin);

函数名称:FileSetAttr
函数说明:更改指定文件的属性参数,如果操作成功,则返回0,函数原型如下;
int __fastcall FileSetAttr(const System::AnsiString FileName,int Attr);

函数名称:FileSetDate
函数说明:更改指定文件的DOS时间标签,如果操作成功,返回0,否则返回错误代码,函数原型如下:
int __fastcall FileSetDate(int Handle,int Age);

函数名称:FileWrite
函数说明:将缓冲区的数据写入到指定的文件的当前位置中去如果操作成功,函数返回实际写入的字节数,如果返回为-1,则表示操作产生错误,函数原型如下:
int __fastcall FileWrite(int Handle,const void *Buffer,int Count);

函数名称:FindClose
函数说明:释放FindFirst操作所申请的内存资源,函数原型如下:
void __fastcall FindClose(TSearchRec &F);

函数名称:FindFirst
函数说明:在指定的文件目录内,搜寻符合特定属性参数的文件,如果成功地查找到符合条件的文件,则函数返回0,否则函数返回一个错误代码,函数原型如下:
int __fastcall FindFirst(const System::AnsiString Path,int Attr,TSearchRec &F);

函数名称:FindNext
函数说明:继续搜寻FindFirst所指定属性参数的文件,如果成功地查找到符合条件的文件,则函数返回0,否则函数返回一个错误代码,函数原型如下:
int __fastcall FindNext(TSearchRec &F);
// 本文转自 C++Builder 研究 - http://www.ccrun.com/article.asp?i=983&d=22l01d

函数名称:RenameFile
函数说明:更改指定文件的名称,如果操作成功,则函数返回真,函数原型如下:
bool __fastcall RenameFile(const AnsiString OldName, const AnsiString NewName);

--------------------
磁盘目录管理
--------------------
函数名称:CreateDir
函数说明:创建新的目录,如果操作成功,返回真,否则返回假,函数原型如下:
bool __fastcall CreateDir(const AnsiString Dir);

函数名称:DiskFree
函数说明:返回指定磁盘的剩余空间,如果操作成功,返回剩余磁盘空间,如果操作失败,则返回-1,函数原型如下:
int __fastcall DiskFree(Byte Drive);

函数名称:DiskSize
函数说明:返回指定磁盘的空间,如果操作成功,返回磁盘空间,如果操作失败,则返回-1,函数原型如下:
int __fastcall DiskSize(Byte Drive);

函数名称:GetCurrentDir
函数说明:返回当前工作目录,函数原型如下:
AnsiString __fastcall GetCurrentDir();

函数名称:RemoveDir
函数说明:删除指定的目录,如果操作成功,返回真,否则返回假,函数原型如下:
bool __fastcall RemoveDir(const AnsiString Dir);

函数名称:SetCurrentDir
函数说明:设置当前工作目录,如果操作成功,则返回真,函数原型如下:
bool __fastcall SetCurrentDir(const AnsiString Dir);

--------------------
字符串操作
--------------------
函数名称:CompareStr
函数说明:比较两个AnsiString字符串,函数原型如下:
int __fastcall CompareStr(const AnsiString S1, const AnsiString S2);

函数名称:CompareText
函数说明:比较两个AnsiString字符串,函数原型如下:
int __fastcall CompareText(const AnsiString S1, const AnsiString S2);

函数名称:LowerCase
函数说明:将指定的AnsiString字符串转换为小写形式,函数原型如下:
AnsiString __fastcall LowerCase(const AnsiString S);

函数名称:StrAlloc
函数说明:为字符串分配指定字节的内存,并返回内存指针,函数原型如下:
char * __fastcall StrAlloc(Cardinal Size);

函数名称:StrBufSize
函数说明:返回*Str所指向内存的大小,函数原型如下:
Cardinal __fastcall StrBufSize(const char * Str);

函数名称:StrCat
函数说明:连接两个字符串,并返回目的字符串指针,函数原型如下:
char * __fastcall StrCat(char * Dest, const char * Source);

函数名称:StrComp
函数说明:两个字符串相到比较,返回比较的结果,函数原型如下:
int __fastcall StrComp(const char * Str1, const char * Str2);

函数名称:StrCopy
函数说明:将源字符串拷贝到目的字符串中,函数原型如下:
char * __fastcall StrCopy(char * Dest, const char * Source);

函数名称:StrECopy
函数说明:将源字符串拷贝到目的字符串中,并返回目的字符串结尾指针,函数原型如下:

char * __fastcall StrECopy(char * Dest, const char * Source);

函数名称:StrEnd
函数说明:返回字符串结尾指针,函数原型如下:
char * __fastcall StrEnd(const char * Str);

函数名称:StrIComp
函数说明:两个字符串相互比较(不论大小写),返回比较的结果,函数原型如下:
int __fastcall StrIComp(const char * Str1, const char * Str2);

函数名称:StrLCat
函数说明:将指定数目的源字符串连接到目的字符串,并返回目的字符串指针,函数原型如下:
char * __fastcall StrLCat(char * Dest, const char * Source, Cardinal MaxLen);

函数名称:StrLComp
函数说明:对两个字符串指定数目的字符进行比较操作,函数原型如下:
int __fastcall StrLComp(const char * Str1, const char * Str2, Cardinal MaxLen);

函数名称:StrLCopy
函数说明:将源字符串指定数目的字符拷贝到目的字符串中,并返回目的字符串指针,函数原型如下:
char * __fastcall StrLCopy(char * Dest, const char * Source, Cardinal MaxLen);

函数名称:StrLen
函数说明:返回字符串的长度,函数原型如下:
Cardinal __fastcall StrLen(const char * Str);

函数名称:StrLower
函数说明:将字符串转换为小写形式,函数原型如下:
char * __fastcall StrLower(char * Str);

函数名称:StrMove
函数说明:从源字符串向目的字符串拷贝指定数目的字符,函数原型如下:
char * __fastcall StrMove(char * Dest, const char * Source, Cardinal Count);

函数名称:StrNew
函数说明:在堆中为指定字符串分配空间,并将字符串拷贝到此空间中,函数原型如下:
char * __fastcall StrNew(const char * Str);

函数名称:StrPas
函数说明:将指定的字符串转换为AnsiString类型字符串对象,函数原型如下:
AnsiString __fastcall StrPas(const char * Str);

函数名称:StrPCopy
函数说明:将AnsiString类型的源字符串拷贝到目的字符串中,并返回目的字符串指针,函数原型如下:
char * __fastcall StrPCopy(char * Dest, const AnsiString Source);

函数名称:StrPLCopy
函数说明:将源字符串(AnsiString类型)指定数目的字符拷贝到目的字符串中,并返回目的字符串指针,函数原型如下:
char * __fastcall StrPLCopy(char * Dest, const AnsiString Source, Cardinal MaxLen);

函数名称:StrPos
函数说明:在Strl所指定的字符串中寻找Str2所指定的子字符串,并返回Str2在Str2中第一个子字符的指针,函数原型如下:
char * __fastcall StrPos(const char * Str1, const char * Str2);

函数名称:StrRScan
函数说明:在指定的字符串中寻找特定的字符,并返回字符串中最后一个特定字符的指针,函数原型如下:
char * __fastcall StrRScan(const char * Str, char Chr);

函数名称:StrScan
函数说明:在指定的字符串中寻找特定的字符,并返回字符串中第一个特定字符的指针,函数原型如下:
char * __fastcall StrScan(const char * Str, char Chr);

函数名称:StrUpper
函数说明:将字符串转换为大写形式,函数原型如下:
char * __fastcall StrUpper(char * Str);

函数名称:UpperCase
函数说明:将指定的AnsiString字符串转换为大写形式,函数原型如下:
AnsiString __fastcall UpperCase(const AnsiString S);

--------------------
类型转换
--------------------
函数名称:FloatToStr
函数说明:将浮点数转换为AnsiString字符串,函数原型如下:
AnsiString __fastcall FloatToStr(Extended Value);

函数名称:FloatToStrF
函数说明:将浮点数转换为指定格式的AnsiString字符串,函数原型如下:
AnsiString __fastcall FloatToStrF(Extended Value, TFloatFormat Format,int Precision, int Digits);

函数名称:IntToHex
函数说明:将整数转换为十六进制字符串,函数原型如下:
AnsiString __fastcall IntToHex(int Value, int Digits);

函数名称:IntToStr
函数说明:将整数转换为AnsiString字符串,函数原型如下:
AnsiString __fastcall IntToStr(int Value);

函数名称:StrToFloat
函数说明:将AnsiString字符串转换为一个浮点数值,函数原型如下:
Extended __fastcall StrToFloat(const AnsiString S);

函数名称:StrToInt
函数说明:将AnsiString字符串转换为整数值,如果不能进行转换,则产生EConvertError异常,函数原型如下:
int __fastcall StrToInt(const AnsiString S);

函数名称:StrToIntDef
函数说明:将AnsiString字符串转换为一个数值,函数原型如下:
int __fastcall StrToIntDef(const System::AnsiString S,int Default);

--------------------
时间日期管理
--------------------
函数名称:Date
函数说明:返回TDateTime对象,包含当前的年月日信息,函数原型如下:
System::TDateTime __fastcall Date(void);

函数名称:DateTimetoStr
函数说明:将TDateTime对象转换为字符串对象,函数原型如下:
AnsiString __fastcall DateTimeToStr(System::TDateTime DateTime);

函数名称:DatetimeToString
函数说明:将TDateTime对象转换为指定格式的字符串对象,函数原型如下:
void __fastcall DateTimeToString(AnsiString &Result, const AnsiString Format,System::TDateTime DateTime);

函数名称:DateTimeToSystemTime
函数说明:将TDateTime对象转换为操作系统时间,函数原型如下:
void __fastcall DateTimeToSystemTime( System::TDateTime DateTime, _SYSTEMTIME &SystemTime);

函数名称:DateToStr
函数说明:将TDateTime对象(包含当前年月日信息)转换为字符串对象,函数原型如下:
AnsiString __fastcall DateToStr(System::TDateTime Date);

函数名称:Now
函数说明:返回TDateTime对象,获取当前的日期和时间信息,函数原型如下:
System::TDateTime __fastcall Now(void);

函数名称:StrToDate
函数说明:将字符串对象转换为年月日对象,函数原型如下:
System::TDateTime __fastcall StrToDate(const AnsiString S);

函数名称:StrToDateTime
函数说明:将字符串对象转换为年月日时间对象,函数原型如下:
System::TDateTime __fastcall StrToDateTime(const AnsiString S);

函数名称:StrToTime
函数说明:将字符串对象转换时间对象,函数原型如下:
System::TDateTime __fastcall StrToTime(const AnsiString S);

函数名称:SystemTimeToDateTime
函数说明:将操作系统时间转换为TDateTime对象,函数原型如下:
System::TDateTime __fastcall SystemTimeToDateTime(const _SYSTEMTIME &SystemTime);

函数名称:Time
函数说明:返回TDateTime对象,包含当前的时间信息,函数原型如下:
System::TDateTime __fastcall Time(void);

函数名称:TimeToStr
函数说明:将当前日期转换为字符串对象,函数原型如下:
AnsiString __fastcall TimeToStr(System::TDateTime Time);


本文档是ccrun(老妖)根据网上资料整理而成。

Delphi中属性的使用(unit2)

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes;

type
// 基类employee
employee=class
protected
name:string; // 姓名
empno:string; // 雇员号
accumpay:real;// 月薪
public
constructor create();// 构造函数
Procedure pay(); Virtual; // 计算月薪函数(虚拟方法)
Procedure displaystatus(); Virtual;// 显示信息函数(虚拟方法)
end;

//技术员类technician
technician=class(employee)
private
hrRate:string;//每小时酬金
hr:string; //当月工作时数
function GetHourlyRate():string;
procedure SetHourlyRate(Value: string);
function GetWorkHours():string;
procedure SetWorkHours(Value: string);

public
property MyHourlyRate: string read GetHourlyRate write SetHourlyRate;
property MyWorkHours: string read GetWorkHours write SetWorkHours;
Procedure pay(); override; //计算月薪函数(覆盖基类中同名方法)
Procedure displaystatus();override; //显示信息函数(覆盖基类中同名方法)
end;

//销售员类(派生于employee)
salesman=class(employee)
private
comm:string;//提取销售额的百分比
sale:string;//销售额
function GetCommrateRate():string;
procedure SetCommrateRate(Value: string);
function GetSales():string;
procedure SetSales(Value: string);
public
property MyCommRate: string read GetCommrateRate write SetCommrateRate;
property MySales: string read GetSales write SetSales;
Procedure pay(); override; //计算月薪函数(覆盖基类中同名方法)
Procedure displaystatus(); override; //显示信息函数(覆盖基类中同名方法)
end;

var
tech: technician;
sales: salesman;
name1,number,result1: string;

implementation
//employee类的函数实现
constructor employee.create();
begin
name:=name1; // name1为存放雇员姓名的全局变量
empno:=number; // number为存放雇员号的全局变量
accumpay:=0.0;
end;

Procedure employee.pay();
begin
end;

Procedure employee.displaystatus();
begin
end;

//技术员类的函数实现
Procedure technician.pay();
begin
accumpay:=strtofloat(GetHourlyRate)*strtofloat(GetWorkHours);
end;

Procedure technician.displaystatus();
begin
result1:=empno+'号技术员'+name+'的本月工资为 '+floattostr(accumpay);
end;
//技术员工资结算
function technician.GetHourlyRate(): string;
begin
GetHourlyRate:=hrRate;
end;
procedure technician.SetHourlyRate(Value: string);
begin
hrRate:=Value;
end;
function technician.GetWorkHours(): string;
begin
GetWorkHours:=hr;
end;
procedure technician.SetWorkHours(Value: string);
begin
hr:=value;
end;

//销售员类的函数实现
Procedure salesman.pay();
begin
accumpay:=strtofloat(GetCommrateRate)*strtofloat(GetSales);
end;

Procedure salesman.displaystatus();
begin
result1:=empno+'号销售员'+name+'的本月工资为 '+floattostr(accumpay);
end;
//销售人员工资结算
function salesman.GetCommrateRate(): string;
begin
GetCommrateRate:=comm;
end;
procedure salesman.SetCommrateRate(Value: string);
begin
comm:=value;
end;
function salesman.GetSales(): string;
begin
GetSales:=sale;
end;
procedure salesman.SetSales(Value: string);
begin
sale:=value;
end;

end.

Delphi中属性的使用(unit1)

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm1 = class(TForm)
Label1: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
tch: TGroupBox;
sls: TGroupBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
jsyno: TEdit;
jsyxm: TEdit;
hours: TEdit;
Label5: TLabel;
xsyno: TEdit;
Label6: TLabel;
xsyxm: TEdit;
xsl: TEdit;
Label7: TLabel;
Label8: TLabel;
result: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
lblHrRate: TLabel;
edtHrRate: TEdit;
lblComm: TLabel;
edtComm: TEdit;
GroupBox3: TGroupBox;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ResetTech(flag: boolean); //设置只读属性
procedure ResetSale(flag: boolean);
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject); //flag标志着只读属性,true则只读,false则可修改
procedure SetEmptyTech();
procedure SetEmptySale();
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;
{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
t1: technician;
s1: salesman;
begin
if RadioButton1.Checked =true then
begin
// 计算技术员的月薪
number:=jsyno.Text ;
name1:= jsyxm.Text ;
t1:=technician.create ();
t1.MyHourlyRate := edtHrRate.Text;
t1.MyWorkHours := hours.Text;
t1.pay ();
t1.displaystatus ();
end
else begin
// 计算销售员的月薪
number:= xsyno.Text ;
name1:= xsyxm.Text ;
s1:=salesman.create ();
s1.MySales := xsl.Text;
s1.MyCommRate := edtComm.Text;
s1.pay ();
s1.displaystatus ();
end;
// 将信息显示在result文本框中
SetEmptyTech();
SetEmptySale();
result.Text :=result1;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
form1.Close;
end;

procedure TForm1.ResetTech(flag: boolean); //根据radio button选择情况设置各输入组的只读情况
begin
if flag = true then
begin
jsyno.ReadOnly := true;
jsyxm.ReadOnly := true;
hours.ReadOnly := true;
edtHrRate.ReadOnly := true;
jsyno.Enabled := false;
jsyxm.Enabled := false;
hours.Enabled := false;
edtHrRate.Enabled := false;
end
else begin
jsyno.ReadOnly := false;
jsyxm.ReadOnly := false;
hours.ReadOnly := false;
edtHrRate.ReadOnly := false;
jsyno.Enabled := true;
jsyxm.Enabled := true;
hours.Enabled := true;
edtHrRate.Enabled := true;
end;
end;

procedure TForm1.ResetSale(flag: boolean);
begin
if flag = true then
begin
xsyno.ReadOnly := true;
xsyxm.ReadOnly := true;
xsl.ReadOnly := true;
edtComm.ReadOnly := true;
xsyno.Enabled := false;
xsyxm.Enabled := false;
xsl.Enabled := false;
edtComm.Enabled := false;
end
else begin
xsyno.ReadOnly := false;
xsyxm.ReadOnly := false;
xsl.ReadOnly := false;
edtComm.ReadOnly := false;
xsyno.Enabled := true;
xsyxm.Enabled := true;
xsl.Enabled := true;
edtComm.Enabled := true;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if RadioButton1.Checked =true then//选中了技术员
begin
ResetTech(false); //将技术员的只读属性设置为false
ResetSale(true);//将销售员的只读属性设置为true
end
else begin
ResetTech(true); //将技术员的只读属性设置为true
ResetSale(false);//将销售员的只读属性设置为false
end;
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
ResetTech(false); //将技术员的只读属性设置为false
ResetSale(true);//将销售员的只读属性设置为true
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
ResetTech(true); //将技术员的只读属性设置为true
ResetSale(false);//将销售员的只读属性设置为false
end;

procedure TForm1.SetEmptySale;
begin
xsyno.Text := '';
xsyxm.Text := '';
xsl.Text := '';
edtComm.Text := '';
end;

procedure TForm1.SetEmptyTech;
begin
jsyno.Text := '';
jsyxm.Text := '';
hours.Text := '';
edtHrRate.Text := '';
end;

end.
Powered By Blogger