DELPHI自己整理的笔记
1:如果编译的时候,经常出现类似这种警告
warning W1005: W1005 Unit 'FileCtrl' is specific to a platform
warning W1002: W1002 Symbol 'FindData' is specific to a platform
就在Interface 与 Users 之间,也就是Users之前
加上{$WARN UNIT_PLATFORM OFF}
{$WARN SYMBOL_PLATFORM OFF}
2:查看一个字符串中有多少个汉字,同时用这种方法,可以得到多少汉字,多个英文
var
ans: AnsiString;
wis: WideString;
sub: Integer; // 汉字的个数
Begin
ans := '盗版delphi';
wis := WideString(ans);
sub := Length(ans) - Length(wis);
3:树上定位到了结点, 但滚动条没有下拉,看不到, 这以加上
Node.MakeVisible;
这样就会定位到,并且显示当前行,
4:Delphi 中, 取颜色的 RGB 值
Form1.Canvas.Pen.Color := clBtnFace;
mmo1.Lines.Add('Red := ' + IntToStr(GetRValue(Form1.Canvas.Pen.Color)));
mmo1.Lines.Add('Green := ' + IntToStr(GetGValue(Form1.Canvas.Pen.Color)));
mmo1.Lines.Add('Blue := ' + IntToStr(GetBValue(Form1.Canvas.Pen.Color)));
5:判断一个控件,是否有该属性.
function HaveProperty(const AComponent: TObject; AProperty: string): boolean;
begin
Result := IsPublishedProp(AComponent, AProperty);
end
测试:
if HaveProperty(btn1, 'Font') then
ShowMessage('存在')
else
ShowMessage('不存在');
------
if HaveProperty(btn1.Font, 'ddda') then
ShowMessage('存在')
else
ShowMessage('不存在');
6:DELPHI对象赋值
Delphi的对象之间赋值主要要注意几个方面的问题:
7: 怎样删除一个里面有文件的文件夹 连文件一起删掉 求具体代码 谢谢
function
DeleteDirectory(
const
DirName:
string
;
const
UI:
Boolean
=
False
):
Boolean
;
{
删除目录
}
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo),
0
);
with
fo
do
begin
Wnd := GetActiveWindow;
wFunc := FO_DELETE;
pFrom :=
PChar
(DirName + #
0
);
pTo := #
0
#
0
;
fFlags := FOF_NOCONFIRMATION + FOF_SILENT;
end
;
Result := (SHFileOperation(fo) =
0
);
end
;
function
ClearDirectory(
const
DirName:
string
;
const
IncludeSub, ToRecyle:
Boolean
):
Boolean
;
{
清除目录
}
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo),
0
);
with
fo
do
begin
Wnd := GetActiveWindow;
wFunc := FO_DELETE;
pFrom :=
PChar
(DirName +
'\*.*'
+ #
0
);
pTo := #
0
#
0
;
fFlags := FOF_SILENT
or
FOF_NOCONFIRMATION
or
FOF_NOERRORUI
or
(Ord(
not
IncludeSub) * FOF_FILESONLY)
or
(ORd(ToRecyle)
or
FOF_ALLOWUNDO);
end
;
Result := (SHFileOperation(fo) =
0
);
end
;
uses
IOUtils;
procedure TForm1.Button1Click(Sender: TObject);
begin
TDirectory.Delete('D:\TDDownload\fa', true);
end;
true时可以删除非空文件夹