Borland Delphi一句话帮助

作者在 2007-01-14 00:02:00 发布以下内容
1. 如果想你的程序能够正确处理异常情况的话,请引用SysUtils.pas单元,否则即使程序使用了try。。。except。。。也不能正确捕获异常。
2. 定义常量字符串的一种方式
resourcestring
aa='aaaa';
raise Exception.CreateRes(@aa);
3. 字符串常量数组的初始化
const constarray:array [0..2] of string=(‘first’,’second’,’third’);
4. 结构体初始化
type Tstructinit=record
A1:integer;
A2:array [0..2] of integer;
End;
Const m_structinit:Tstructinit=(A1:0;A2:(0,1,2));
5. 多维数组的长度
var array2:array of array of integer;
setlength(array2,2,2);
6. 使用Create和New开辟的空间都存在于堆中,不能自动释放,建议使用FreeAndNil释放/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, 参数以及局部变量存在于栈中,自动释放。
7. SizeOf不适合于对象,返回的总是4;对于固定类型可以正确返回.
8. Create(nil)需要手工释放,Creat(self)会随着拥有者的释放而释放.
9. 动态改变已定义常量的值
procedure ChangeConst(const Const;var Value;Size:Integer);
begin
Move((@Value)^,(@Constant)^,Size);
End;
10. 进行删除操作的时候循环使用DownTo,会避免错误.

11. 汉字的Ascii码>128,可以用它来判别是否为汉字
12. dll编写中,需要使用Sharemem单元来引用BORLANDMM.DLL内存管理.
13. PostMessage只将消息放到消息队列中,需要排队等待处理。
SendMessage绕过消息队列直接发送到窗口过程,等到消息处理返回值才返回.
14. 鼠标移入移出消息:CM_MOUSEENTER,CM_MOUSELEAVE
15. 关机消息WM_QUERYENDSESSION
16. 可以利用ThintWindow和类的方法ActivateHint来创建浮动窗体.
17. 调出文件属性对话框
uses ShellAPI;
function ShowFileProperties(FileName/DownloadFiles\a200507\2005-07-27\@ String; Wnd/DownloadFiles\a200507\2005-07-27\@ HWND):Boolean;
var
sfi/DownloadFiles\a200507\2005-07-27\@ TSHELLEXECUTEINFO;
begin
with sfi do
begin
cbSize := SizeOf(sfi);
lpFile := PAnsiChar(FileName);
Wnd := Wnd;
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_INVOKEIDLIST or SEE_MASK_FLAG_NO_UI;
lpVerb := PAnsiChar('properties');
lpIDList := nil;
lpDirectory := nil;
nShow := 0;
hInstApp := 0;
lpParameters := nil;
dwHotKey := 0;
hIcon := 0;
hkeyClass := 0;
hProcess := 0;
lpClass := nil;
end;
Result := ShellExecuteEX(@sfi);
end;
procedure TForm1.Button1Click(Sender/DownloadFiles\a200507\2005-07-27\@ TObject);
begin
ShowFileProperties('c:\AA.txt'/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, Handle);
end;
18. 更改系统时间
uses Windows,Dialogs,Forms;
var MyTime:TsystemTime;
begin
FillChar(MyTime,sizeof(MyTime),#0);
MyTime.wYear:=2003;
MyTime.wMonth:=06;
MyTime.wDay:=01;
If not SetSystem(MyTime) then
Showmessage(‘Failure’);
End;
19. 复制文件夹Xcopy
. procedure Xcopy(SourceDir,DestinationDir:String);
var
Search /DownloadFiles\a200507\2005-07-27\@ TSearchRec;
Rec /DownloadFiles\a200507\2005-07-27\@ word;
Begin
SourceDir := SourceDir + '\';
Rec := FindFirst(SourceDir + '*.*'/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, faAnyFile/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, Search);
While Rec = 0 Do
Begin
If Search.Name[1] <> '.' Then
Begin

计算机教程delphi一句话帮助来自www.itwen.comIT WEN计算机教程网

If (Search.Attr And faDirectory) = faDirectory Then
Begin
Windows.CreateDirectory(PChar(DestinationDir + '\' + Search.Name)/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, nil);
FileSetAttr(DestinationDir + '\' + Search.Name/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, FileGetAttr(SourceDir + '\' + Search.Name));
X_Copy(SourceDir + '\' + Search.Name/DownloadFiles\a200507\2005-07-27\/DownloadFiles\a200507\2005-07-27\, DestinationDir + '\' + S

转移技术贴 | 阅读 1580 次
文章评论,共0条
游客请输入验证码
浏览80659次