取得该快捷方式的指向EXE
关键词:快捷方式 LNK
unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants,
Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1
= class(TForm)
Button1: TButton;
procedure Button1Click(Sender:
TObject);
private
{ Private declarations }
public
{ Public
declarations }
end;
var
Form1:
TForm1;
implementation
uses activex,comobj,shlobj;
{$R
*.dfm}
function ResolveLink(const ALinkfile: String):
String;
var
link: IShellLink;
storage: IPersistFile;
filedata:
TWin32FindData;
buf: Array[0..MAX_PATH] of Char;
widepath:
WideString;
begin
OleCheck(CoCreateInstance(CLSID_ShellLink, nil,
CLSCTX_INPROC_SERVER, IShellLink,
link));
OleCheck(link.QueryInterface(IPersistFile, storage));
widepath :=
ALinkFile;
Result := 'unable to resolve link';
If
Succeeded(storage.Load(@widepath[1], STGM_READ)) Then
If
Succeeded(link.Resolve(GetActiveWindow, SLR_NOUPDATE)) Then
If
Succeeded(link.GetPath(buf, sizeof(buf), filedata, SLGP_UNCPRIORITY))
Then
Result := buf;
storage := nil;
link:= nil;
end;
//
用法:
procedure TForm1.Button1Click(Sender:
TObject);
begin
ShowMessage(ResolveLink('C:\delphi
7.lnk'));
end;
end.
-
delphi 开发和测试2004-2006年总结经验【二】
2007-01-25 15:02:41
FindFirst 的用法2007-04-29 09:15FindFirst('D:\delphi\*.jpg',$00000001,sr);
Constant Value Description
faReadOnly $00000001 Read-only files
faHidden $00000002 Hidden files
faSysFile $00000004 System files
faVolumeID $00000008 Volume ID files
faDirectory $00000010 Directory files
faArchive $00000020 Archive files
faAnyFile $0000003F Any file________________________________________________
*****************************************************************************1.要注意大小写,那是个常量
2.可以用API findfirstfile
下面是关于 findfirstfile的说明(英文的)
Unit
Windows.Pas
Syntax
FindFirstFile(
lpFileName: PChar; {a pointer to a filename}
var lpFindFileData: TWin32FindData {a pointer to a TWin32FindData structure}
): THandle; {returns a search handle}
Description
This function searches the current directory for the first file that matches the filename specified by the lpFileName parameter. This function will find both files and subdirectories, and the filename being searched for can contain wild cards.
Parameter:
lpFileName: A pointer to a null terminated string containing the path and filename for which to search. This filename may contain wild cards .
lpFindFileData: A pointer to a TWin32FindData data structure containing information about the file or subdirectory that was found. The TWin32FindData data structure is defined as:
TWin32FindData = record
dwFileAttributes: DWORD; {file attributes}
ftCreationTime: TFileTime; {file creation time}
ftLastAccessTime: TFileTime; {last file access time}
ftLastWriteTime: TFileTime; {last file modification time}
nFileSizeHigh: DWORD; {high double word of file size}
nFileSizeLow: DWORD; {low double word of file size}
dwReserved0: DWORD; {reserved for future use}
dwReserved1: DWORD; {reserved for future use}
cFileName: array[0..MAX_PATH - 1] of AnsiChar; {long file name}
cAlternateFileName: array[0..13] of AnsiChar; {short file name}
end;
dwFileAttributes: Specifies the file attribute flags for the file. See the GetFileAttributes function for a list of possible file attribute flags.
ftCreationTime: Specifies the time that the file was created.
ftLastAccessTime: Specifies the time that the file was last accessed.
ftLastWriteTime: Specifies the time that the file was last modified.
nFileSizeHigh: Specifies the high order double word of the file size.
nFileSizeLow: Specifies the low order double word of the file size.
dwReserved0: This member is reserved for future use, and its value is undetermined.
dwReserved1: This member is reserved for future use, and its value is undetermined.
cFileName: A null terminated string containing the long version of the filename.
cAlternateFileName: A null terminated string containing the short (8.3) version of the filename.
Return Value
If the function succeeds, it returns a search handle that can be used in subsequent calls to FindNextFile. If the function fails, it returns INVALID_HANDLE_VALUE.________________________________________________
*****************************************************************************FindFirst('D:\图像数据\*.jpg',fareadonly,sr);
为什么提示“ fareadonly” 错误!
我已经找到问题的原因! 不是大小写的问题!
而是! 在我的代码里面我用到 TADOquery里面的字段属性,刚好
在这个字段里面有这个 fareadOnly 的常量, 而造成冲突。所以
$00000001这个代替fareadOnly就没有问题了!________________________________________________
*****************************************************************************不错的例子:
procedure TForm1.Button1Click(Sender: TObject);
var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then
FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then
FileAttrs := FileAttrs + faAnyFile;
with StringGrid1 do
begin
RowCount := 0;
if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then
begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
end;用Delphi实现子目录级的文件查询在应用实践中,我们经常会用到文件查询功能。通过Win95中提供的查找功能,我们可以方便的找出磁盘上任何子目录下的文件,其原因是该查找功能可以遍历指定目录下的所有子目录中的文件。从编程角度讲,它实现了子目录级的文件查询。其实,这项功能并不难实现,关键是能理解并掌握懙莨閽这种程序设计思路。本人用Delphi实现了该项功能(任意子目录级),由于使用了懙莨閽,程序思路清晰,代码量小。
实现方法:
1. 获取当前目录下的所有下一级子目录。
2. 存入字符串列表中(Tstrings)。
其中,用到了几个API函数。
FindFirst 是找出指定目录下第一个文件或目录。
FindNext 一般和FindFirst配合使用,用来找出下一个文件或目录。
FindClose 用来关闭查询。
(以上函数Delphi在线帮助中有详尽解释,在此不赘述);
3. 用FileExists函数查找当前目录,
4. 寻找是否有满足条件的文件存在,
5. 依次使各个子目录成为当前目录,
6. 递归调用本函数,
7. 释放资源,
8. 返回查询结果。
代码如下:
1. 从搜索记录中判断是否是子目录。
function IsValidDir(SearchRec:TSearchRec):Boolean;
begin
if (SearchRec.Attr=16) and
(SearchRec.Name<>'.') and
(SearchRec.Name<>'..') then
Result:=True
else
Result:=False;
end;
2. 这是查询主体函数。
参数介绍:
Mainpath: 指定的查询目录。
Filename: 欲查询的文件。
Foundresult: 返回的含完整路径的匹配文件(可能有多个)。
如果有匹配文件,函数返回True,否则,返回False;
function SearchFile(mainpath:string; filename:string;
var foundresult:TStrings):Boolean;
var i:integer;
Found:Boolean;
subdir1:TStrings;
searchRec:TsearchRec;
begin
found:=false;
if Trim(filename)<>'' then
begin
subdir1:=TStringList.Create;//字符串列表必须动态生成
//找出所有下级子目录。
if (FindFirst(mainpath+'*.*', faDirectory, SearchRec)=0) then
begin
if IsValidDir(SearchRec) then
subdir1.Add(SearchRec.Name);
while (FindNext(SearchRec) = 0) do
begin
if IsValidDir(SearchRec) then
subdir1.Add(SearchRec.Name);
end;
end;
FindClose(SearchRec);
//查找当前目录。
if FileExists(mainpath+filename) then
begin
found:=true;
foundresult.Add(mainpath+filename);
end;
//这是递归部分,查找各子目录。
for i:=0 to subdir1.Count-1 do
found:=Searchfile(mainpath+subdir1.Strings[i]+
'\',Filename,foundresult)or found;
//资源释放并返回结果。
subdir1.Free;
end;
result:=found;
end;取得该快捷方式的指向EXE关于文件操作集锦
在Delphi中获取和修改文件的时间在Delphi中获取和修改文件的时间关键词:文件修改时间
本文介绍了在Delphi中利用系统函数和Windows API函数调用来获取和修改文件的时间信息的方法。
熟 悉Windows 95/98的朋友一定经常会用单击鼠标右键的方法来查看所选定的文件的属性信息。在属性菜单中会列出该文件的创建时间、修改时间和访问时间。这些信息常常 是很有用的,它们的设置一般都是由操作系统(也就是由Dos/Windows等等)自动完成的,不会让用户轻易修改。
这里,我向大家 介绍在Delphi中如何实现文件时间的获取和修改方法。Delphi中提供了很完备的Windows API函数的调用接口,可以方便的进行高级Windows编程。利用Delphi中的FindFirst函数可以得到一个文件的属性记录,该记录中的 FindData域中就记载了详细的文件时间信息。然而遗憾的是,FindData中的时间信息是不能直接得到的。因此,有人(编者按:很遗憾不知此人姓 名)编写了一个转换函数来完成文件时间格式的转换。下面给出了具体的实现方法,仅供参考:
function CovFileDate(Fd:_FileTime):TDateTime;
{ 转换文件的时间格式 }
var
Tct:_SystemTime;
Temp:_FileTime;
begin
FileTimeToLocalFileTime(Fd,Temp);
FileTimeToSystemTime(Temp,Tct);
CovFileDate:=SystemTimeToDateTime(Tct);
end;
有了上面的函数支持,我们就可以获取一个文件的时间信息了。以下是一个简单的例子:
procdeure GetFileTime(const Tf:string);
{ 获取文件时间,Tf表示目标文件路径和名称 }
const
Model=yyyy/mm/dd,hh:mm:ss; { 设定时间格式 }
var
Tp:TSearchRec; { 申明Tp为一个查找记录 }
T1,T2,T3:string;
begin
FindFirst(Tf,faAnyFile,Tp); { 查找目标文件 } T1:=FormatDateTime(Model,
CovFileDate(Tp.FindData.ftCreationTime)));
{ 返回文件的创建时间 }
T2:=FormatDateTime(Model,
CovFileDate(Tp.FindData.ftLastWriteTime)));
{ 返回文件的修改时间 }
T3:=FormatDateTime(Model,Now));
{ 返回文件的当前访问时间 }
FindClose(Tp);
end;
设 置文件的时间要复杂一些,这里介绍利用Delphi中的DataTimePicker组件来辅助完成这一复杂的操作。下面的例子利用了四个 DataTimePicker组件来完成文件创建时间和修改时间的设置。注意:文件的访问时间用修改时间来代替。使用下面的例子时,请在您的Form上添 加四个DataTimePicker组件。其中第一和第三个DataTimePicker组件中的Kind设置为dtkDate,第二个和第四个 DataTimePicker组件中的Kind设置为dtkTime.
procedure SetFileDateTime(const Tf:string);
{ 设置文件时间,Tf表示目标文件路径和名称 }
var
Dt1,Dt2:Integer;
Fs:TFileStream;
Fct,Flt:TFileTime;
begin
Dt1:=DateTimeToFileDate(
Trunc(Form1.DateTimePicker1.Date) + Frac(Form1.DateTimePicker2.Time));
Dt2:=DateTimeToFileDate(
Trunc(Form1.DateTimePicker3.Date) + Frac(Form1.DateTimePicker4.Time));
{ 转换用户输入在DataTimePicker中的信息 }
try
FS := TFileStream.Create(Tf, fmOpenReadWrite);
try
if DosDateTimeToFileTime(LongRec(DT1).Hi, LongRec(DT1).Lo, Fct) and
LocalFileTimeToFileTime(Fct, Fct) and
DosDateTimeToFileTime(LongRec(DT2).Hi, LongRec(DT2).Lo, Flt) and
LocalFileTimeToFileTime(Flt, Flt)
then SetFileTime(FS.Handle,
@Fct, @Flt, @Flt);
{ 设置文件时间属性 }
finally
FS.Free;
end;
except
MessageDlg(日期修改操作失败!,
mtError, [mbOk], 0);
{ 因为目标文件正在被使用等原因而导致失败 }
end;
end;
以上简单介绍了文件时间属性的修改方法,请注意:修改文件时间的范围是从公元1792年9月19日开始的,上限可以达到公元2999年或更高。另外,请不要将此技术用于破坏他人文件等非正当途径。从快捷方式取得该快捷方式的指向文档关键词:快捷方式unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses activex,comobj,shlobj;
{$R *.dfm}
function ResolveLink(const ALinkfile: String): String;
var
link: IShellLink;
storage: IPersistFile;
filedata: TWin32FindData;
buf: Array[0..MAX_PATH] of Char;
widepath: WideString;
begin
OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, link));
OleCheck(link.QueryInterface(IPersistFile, storage));
widepath := ALinkFile;
Result := 'unable to resolve link';
If Succeeded(storage.Load(@widepath[1], STGM_READ)) Then
If Succeeded(link.Resolve(GetActiveWindow, SLR_NOUPDATE)) Then
If Succeeded(link.GetPath(buf, sizeof(buf), filedata, SLGP_UNCPRIORITY)) Then
Result := buf;
storage := nil;
link:= nil;
end;
// 用法:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ResolveLink('C:\delphi 7.lnk'));
end;
修改文件的扩展名关键词:扩展名 ChangeFileExt
var
filename:String;
begin
filename := 'abcd.html';
filename := ChangeFileExt(filename, '');
Edit1.Text:=filename;
end;
下面源代码或许对你有些帮助:
Procedure NewTxt;
Var
F : Textfile;
Begin
AssignFile(F, 'c:\ek.txt'); {将文件名与变量 F 关联}
ReWrite(F); {创建一个新的文件并命名为 ek.txt}
Writeln(F, '将您要写入的文本写入到一个 .txt 文件');
Closefile(F); {关闭文件 F}
End;
Procedure OpenTxt;
Var
F : Textfile;
Begin
AssignFile(F, 'c:\ek.txt'); {将文件名与变量 F 关联}
Append(F); {以编辑方式打开文件 F }
Writeln(F, '将您要写入的文本写入到一个 .txt 文件');
Closefile(F); {关闭文件 F}
End;
Procedure ReadTxt;
Var
F : Textfile;
str : String;
Begin
AssignFile(F, 'c:\ek.txt'); {将文件名与变量 F 关联}
Reset(F); {打开并读取文件 F }
Readln(F, str);
ShowMessage('文件有:' +str + '行。');
Closefile(F); {关闭文件 F}
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
NewTxt;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
OpenTxt;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ReadTxt;
end;删除某目录下所有指定扩展名文件//删除某目录下所有指定扩展名文件
function DelFile(sDir,fExt: string): Boolean;
var
hFindfile: HWND;
FindFileData: WIN32_FIND_DATA;
sr: TSearchRec;
begin
sDir:= sDir + '\';
hFindfile:= FindFirstFile(pchar(sDir + fExt), FindFileData);
if hFindFile <> NULL then
begin
deletefile(sDir + FindFileData.cFileName);
while FindNextFile(hFindFile, FindFileData) <> FALSE do
deletefile(sDir + FindFileData.cFileName);
end;
sr.FindHandle:= hFindFile;
FindClose(sr);
end;
function getAppPath : string;
var
strTmp : string;
begin
strTmp := ExtractFilePath(ExtractFilePath(application.Exename));
if strTmp[length(strTmp)] <> '\' then
strTmp := strTmp + '\';
result := strTmp;
end;把音频插进EXE文件并且播放关键词:资源文件步骤1)建立一个SOUNDS.RC文件
使用NotePad记事本-象下面:
#define WAVE WAVEFILE
SOUND1 WAVE "anysound.wav"
SOUND2 WAVE "anthersound.wav"
SOUND3 WAVE "hello.wav"
步骤2)把它编译到一个RES文件
使用和Delphi一起的BRCC32.EXE程序。使用下面的命令行:
BRCC32.EXE -foSOUND32.RES SOUNDS.RC
你应该以'sound32.res'结束一个文件。
步骤3)把它加入你的程序
在DPR文件把它加入{$R*.RES}下面,如下:
{$R SOUND32.RES}
步骤4)把下面的代码加入程序去播放内含的音频
USES MMSYSTEM
Procedure PlayResSound(RESName:String;uFlags:Integer);
var
hResInfo,hRes:Thandle;
lpGlob:Pchar;
Begin
hResInfo:=FindResource(HInstance,PChar(RESName),MAKEINTRESOURCE('WAVEFILE'));
if hResInfo = 0 then
begin
messagebox(0,'未找到资源。',PChar(RESName),16);
exit;
end;
hRes:=LoadResource(HInstance,hResinfo);
if hRes = 0 then
begin
messagebox(0,'不能装载资源。',PChar(RESName),16);
exit;
end;
lpGlob:=LockResource(hRes);
if lpGlob=Nil then
begin
messagebox(0,'资源损坏。',PChar(RESName),16);
exit;
end;
uFlags:=snd_Memory or uFlags;
SndPlaySound(lpGlob,uFlags);
UnlockResource(hRes);
FreeResource(hRes);
End;
步骤5)调用程序,用你在步骤(1)编译的声音文件名。
PlayResSound('SOUND1',SND_ASYNC)
Flags are:
SND_ASYNC = Start playing, and don't wait to return
SND_SYNC = Start playing, and wait for the sound to finish
SND_LOOP = Keep looping the sound until another sound is played
2006-2-16 19:27:29 delphi如何修改文件的时间关键词:文件创建时间 最后修改时间 最后访问时间
在windows下,属性里面有三个日起,创建,修改,存储。我怎么来修改啊?
代码如下:
type
// indicates the file time to set, used by SetFileTimesHelper and SetDirTimesHelper
TFileTimes = (ftLastAccess, ftLastWrite, ftCreation);
function SetFileTimesHelper(const FileName: string; const DateTime: TDateTime; Times: TFileTimes): Boolean;
var
Handle: THandle;
FileTime: TFileTime;
SystemTime: TSystemTime;
begin
Result := False;
Handle := CreateFile(PChar(FileName), GENERIC_WRITE, FILE_SHARE_READ, nil,
OPEN_EXISTING, 0, 0);
if Handle <> INVALID_HANDLE_VALUE then
try
//SysUtils.DateTimeToSystemTime(DateTimeToLocalDateTime(DateTime), SystemTime);
SysUtils.DateTimeToSystemTime(DateTime, SystemTime);
if Windows.SystemTimeToFileTime(SystemTime, FileTime) then
begin
case Times of
ftLastAccess:
Result := SetFileTime(Handle, nil, @FileTime, nil);
ftLastWrite:
Result := SetFileTime(Handle, nil, nil, @FileTime);
ftCreation:
Result := SetFileTime(Handle, @FileTime, nil, nil);
end;
end;
finally
CloseHandle(Handle);
end;
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastAccess(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastAccess);
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastWrite(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastWrite);
end;
//--------------------------------------------------------------------------------------------------
function SetFileCreation(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftCreation);
end;获取文件修改时间varfhandle:Thandle;
s:String;
begin
fhandle:=fileopen('f:\abc.txt',0);
try
s:=datetimetostr(filedatetodatetime(filegetdate(fhandle)));
finally
fileclose(fhandle);
end;
showMessage(s);
end;获得和相应扩展文件名关联的应用程序的名字关键词:扩展名 关联程序名
步骤1)建立一个SOUNDS.RC文件
使用NotePad记事本-象下面:
#define WAVE WAVEFILE
SOUND1 WAVE "anysound.wav"
SOUND2 WAVE "anthersound.wav"
SOUND3 WAVE "hello.wav"
步骤2)把它编译到一个RES文件
使用和Delphi一起的BRCC32.EXE程序。使用下面的命令行:
BRCC32.EXE -foSOUND32.RES SOUNDS.RC
你应该以'sound32.res'结束一个文件。
步骤3)把它加入你的程序
在DPR文件把它加入{$R*.RES}下面,如下:
{$R SOUND32.RES}
步骤4)把下面的代码加入程序去播放内含的音频
USES MMSYSTEM
Procedure PlayResSound(RESName:String;uFlags:Integer);
var
hResInfo,hRes:Thandle;
lpGlob:Pchar;
Begin
hResInfo:=FindResource(HInstance,PChar(RESName),MAKEINTRESOURCE('WAVEFILE'));
if hResInfo = 0 then
begin
messagebox(0,'未找到资源。',PChar(RESName),16);
exit;
end;
hRes:=LoadResource(HInstance,hResinfo);
if hRes = 0 then
begin
messagebox(0,'不能装载资源。',PChar(RESName),16);
exit;
end;
lpGlob:=LockResource(hRes);
if lpGlob=Nil then
begin
messagebox(0,'资源损坏。',PChar(RESName),16);
exit;
end;
uFlags:=snd_Memory or uFlags;
SndPlaySound(lpGlob,uFlags);
UnlockResource(hRes);
FreeResource(hRes);
End;
步骤5)调用程序,用你在步骤(1)编译的声音文件名。
PlayResSound('SOUND1',SND_ASYNC)
Flags are:
SND_ASYNC = Start playing, and don't wait to return
SND_SYNC = Start playing, and wait for the sound to finish
SND_LOOP = Keep looping the sound until another sound is played
delphi如何修改文件的时间关键词:文件创建时间 最后修改时间 最后访问时间
在windows下,属性里面有三个日起,创建,修改,存储。我怎么来修改啊?
代码如下:
type
// indicates the file time to set, used by SetFileTimesHelper and SetDirTimesHelper
TFileTimes = (ftLastAccess, ftLastWrite, ftCreation);
function SetFileTimesHelper(const FileName: string; const DateTime: TDateTime; Times: TFileTimes): Boolean;
var
Handle: THandle;
FileTime: TFileTime;
SystemTime: TSystemTime;
begin
Result := False;
Handle := CreateFile(PChar(FileName), GENERIC_WRITE, FILE_SHARE_READ, nil,
OPEN_EXISTING, 0, 0);
if Handle <> INVALID_HANDLE_VALUE then
try
//SysUtils.DateTimeToSystemTime(DateTimeToLocalDateTime(DateTime), SystemTime);
SysUtils.DateTimeToSystemTime(DateTime, SystemTime);
if Windows.SystemTimeToFileTime(SystemTime, FileTime) then
begin
case Times of
ftLastAccess:
Result := SetFileTime(Handle, nil, @FileTime, nil);
ftLastWrite:
Result := SetFileTime(Handle, nil, nil, @FileTime);
ftCreation:
Result := SetFileTime(Handle, @FileTime, nil, nil);
end;
end;
finally
CloseHandle(Handle);
end;
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastAccess(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastAccess);
end;
//--------------------------------------------------------------------------------------------------
function SetFileLastWrite(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftLastWrite);
end;
//--------------------------------------------------------------------------------------------------
function SetFileCreation(const FileName: string; const DateTime: TDateTime): Boolean;
begin
Result := SetFileTimesHelper(FileName, DateTime, ftCreation);
end;
----------------------------------------------------------------------
获取文件修改时间var
fhandle:Thandle;
s:String;
begin
fhandle:=fileopen('f:\abc.txt',0);
try
s:=datetimetostr(filedatetodatetime(filegetdate(fhandle)));
finally
fileclose(fhandle);
end;
showMessage(s);
end;
获得和相应扩展文件名关联的应用程序的名字关键词:扩展名 关联程序名
uses
{$IFDEF WIN32}
Registry; {We will get it from the registry}
{$ELSE}
IniFiles; {We will get it from the win.ini file}
{$ENDIF}
{$IFNDEF WIN32}
const MAX_PATH = 144;
{$ENDIF}
function GetProgramAssociation (Ext : string) : string;
var
{$IFDEF WIN32}
reg: TRegistry;
s : string;
{$ELSE}
WinIni : TIniFile;
WinIniFileName : array[0..MAX_PATH] of char;
s : string;
{$ENDIF}
begin
{$IFDEF WIN32}
s := '';
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
if reg.OpenKey('.' + ext + '\shell\open\command',
false) <> false then begin
{The open command has been found}
s := reg.ReadString('');
reg.CloseKey;
end else begin
{perhaps thier is a system file pointer}
if reg.OpenKey('.' + ext,
false) <> false then begin
s := reg.ReadString('');
reg.CloseKey;
if s <> '' then begin
{A system file pointer was found}
if reg.OpenKey(s + '\shell\open\command',
false) <> false then
{The open command has been found}
s := reg.ReadString('');
reg.CloseKey;
end;
end;
end;
{Delete any command line, quotes and spaces}
if Pos('%', s) > 0 then
Delete(s, Pos('%', s), length(s));
if ((length(s) > 0) and
(s[1] = '"')) then
Delete(s, 1, 1);
if ((length(s) > 0) and
(s[length(s)] = '"')) then
Delete(s, Length(s), 1);
while ((length(s) > 0) and
((s[length(s)] = #32) or
(s[length(s)] = '"'))) do
Delete(s, Length(s), 1);
{$ELSE}
GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
StrCat(WinIniFileName, '\win.ini');
WinIni := TIniFile.Create(WinIniFileName);
s := WinIni.ReadString('Extensions',
ext,
'');
WinIni.Free;
{Delete any command line}
if Pos(' ^', s) > 0 then
Delete(s, Pos(' ^', s), length(s));
{$ENDIF}
result := s;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetProgramAssociation('gif'));
end;删除目录里的文件但保留目录关键词:删除文件
uses Windows, Classes, ShellAPI;
const
FOF_DEFAULT_IDEAL = FOF_MULTIDESTFILES + FOF_RENAMEONCOLLISION + FOF_NOCONFIRMATION + FOF_ALLOWUNDO +
FOF_FILESONLY + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI + FOF_SIMPLEPROGRESS;
FOF_DEFAULT_DELTREE = FOF_NOCONFIRMATION + FOF_ALLOWUNDO + FOF_NOERRORUI;
FOF_DEFAULT_COPY = FOF_NOCONFIRMATION + FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI + FOF_MULTIDESTFILES;
FOF_DEFAULT_DELFILES = FOF_DEFAULT_DELTREE;
function ShellDeleteFiles( hWnd : THandle ; const DirName : string; Flags : FILEOP_FLAGS; WinTitle : PChar ) : integer;
{---------------------------------------------------------------------------------------------}
{Apaga arquivos/Diretorios atraves do shell do windows}
//Notas: Ver comentario sobre o uso de duplo #0 nos parametros de Origem e destino
var
FileOpShell : TSHFileOpStruct;
Oper : array[0..1024] of char;
begin
if WinTitle <> nil then begin
Flags:=Flags + FOF_SIMPLEPROGRESS;
end;
with FileOpShell do begin
wFunc:=FO_DELETE;
pFrom:=Oper;
pTo:=Oper; //pra garantir a rapadura!
fFlags:=Flags;
lpszProgressTitle:=WinTitle;
Wnd:=hWnd;
hNameMappings:=nil;
fAnyOperationsAborted:=False;
end;
StrPCopy( Oper, DirName );
StrCat(Oper, PChar( ExtractFileName( FindFirstChildFile( DirName )) ) );
Result:=0;
try
while Oper <> EmptyStr do begin
Result:=ShFileOperation( FileOpShell );
if FileOpShell.fAnyOperationsAborted then begin
Result:=ERROR_REQUEST_ABORTED;
break;
end else begin
if Result <> 0 then begin
Break;
end;
end;
StrPCopy(Oper, FindFirstChildFile( DirName ) );
end;
except
Result:=ERROR_EXCEPTION_IN_SERVICE;
end;
end;放置任意的文件到exe文件里关键词:Exe 资源文件 RES
通常在Delphi的应用程序中,我们会调用到很多的资源,例如图片,动画(AVI),声音,甚至于别的执行文件。当然,把这些资源分布到不同的目录不失为一个好办法,但是有没有可能把这些资源编译成标准的windows资源从而链接到一个执行文件里面呢?
我们可以自己做一个RC文件,例如 sample.rc ,RC文件其实就是一个资源文件的描述文本,通过“记事本”程序创建就行了。然后可以输入一些我们要定义的资源,例如:
MEN BITMAP c:\bitmap\men.bitmap
ARJ EXEFILE c:\arj.exe
MOV AVI c:\mov.avi
然后用BRCC32把这个RC文件编译成sample.res(真正的资源文件)。
在Delphi的工程文件中使用 $R 编译指令让Delphi包括资源到EXE文件里面。
{$R sample.res}
这样我们就可以在这个单一的执行文件中调用资源了。举例如下:
EXEFILE:
procedure ExtractRes(ResType, ResName, ResNewName : String);
var
Res : TResourceStream;
begin
Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType)); Res.SavetoFile(ResNewName);
Res.Free;
end;
AVI:
procedure LoadAVI;
begin
{Avi1是一个TAnimate类}
Avi1.ResName:='AVI';
Avi1.Active:=True;
end;
如何把文件删除到回收站中关键词:删除文件 回收站
program del;
uses ShellApi;
{ 利用ShellApi中: function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall; }
Var T:TSHFileOpStruct;
P:String;
begin
P:='C:\Windows\System\EL_CONTROL.CPL';
With T do
Begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=Pchar(P);
fFlags:=FOF_ALLOWUNDO
End;
SHFileOperation(T);
End.
注意:
1. 给出文件的绝对路径名,否则可能不能恢复;
2. MS的文档说对于多个文件,每个文件名必须被#)字符分隔,而整个字符串必须用两个#0结束。
实现打开或运行一个指定文件关键词:打开文件 运行文件 ShellExecute 打开网页
打开Windows已经注册的文件其实很简单,根据以下代码定义一个过程:
procedure URLink(URL:PChar);
begin
ShellExecute(0, nil, URL, nil, nil, SW_NORMAL);
end;
在要调用的地方使用
URLink('Readme.txt');
如果是链接主页的话,那么改用
URLink('http://gui.yeah.net'); -
delphi 开发和测试2004-2006年总结经验【一】
2007-01-25 14:52:26
Delphi教程http://www.bc-cn.net/Article/kfyy/delphi/Index.html
http://www.ibook8.com/Sorting/Catalog17/Sorting_Indate_Desc_1.html
http://www.pcppc.cn/kaifa/Delphi/List_27.html
DELPHI资源文件的常规使用资源文件就是项目中的.res文件,在DELPHI5中project菜单下有Resources项,可以编辑资源,也可以使用VC打开.res 文件进行编辑。
注:DelphiX\Demos\Resxplor\resxplor.exe 可以进行资源文件浏览,可以协助使用资源文件
以下通过代码说明资源文件的使用
使用数据(二行制),对于资源文件来讲是RT_RCDATA类型procedure TForm1.TESTDATEClick(Sender: TObject);
var
n: integer;
hrscr1: HRSRC;
hglobal1: HGLOBAL;
str1: Pchar;
p:pointer;
begin
//查找资源 HInstance 表示使用自身
//可以通过 LoadLibrary('11.exe');调用其他文件
//RCDATA_1数据已经在DELPHI资源管理中RCDATA项目内建立,
hrscr1:= FindResource(HInstance, 'RCDATA_1', RT_RCDATA);
if hrscr1=0 then exit;
//调入资源
hglobal1 := LoadResource(0, hrscr1);
n := SizeofResource(Hinstance,hrscr1);
ShowMessage('数据长度为:=' + inttostr(n));
//返回的为一个指针,本文测试用的是文本文件,
//实际中可以是二进制文件,通过指针P和资源长度N进行访问
str1 := LockResource(hglobal1);
p:= LockResource(hglobal1);
if str1 = nil then exit;
ShowMessage(str1);
showMessage('字符串长度:'+inttostr(length(str1)));
end;
调入图标文件procedure TForm1.iconBoxChange(Sender: TObject);
begin
Image1.Picture.Icon.Handle:=LoadIcon(HInstance,pchar(iconBox.Text));
end;
改变鼠标指针procedure TForm1.currorboxChange(Sender: TObject);
begin
Screen.Cursors[1] := LoadCursor(HInstance,pchar(currorbox.text));
form1.Cursor:=1;
end;
调入Bitmap图片procedure TForm1.LISTBITMAPChange(Sender: TObject);
begin
// Image1
Image1.Picture.Bitmap.Handle:=LoadBitmap(HInstance,pchar(LISTBITMAP.text));
end;
调用其他EXT或DLL文件中的资源procedure TForm1.useloadlibrayClick(Sender: TObject);
var
n:integer;
begin
n:=LoadLibrary('11.exe');
Image1.Picture.Bitmap.Handle:=LoadBitmap(n,pchar(LISTBITMAP.text));
FreeLibrary(n);
end;注册表用Delphi5.0实现注册表监视
http://www.ccw.com.cn/htm/app/aprog/02_1_14_4.asp
delphi添加注册表项和删除是什么
http://zhidao.baidu.com/question/16079362.html
Delphi实现对注册表的监视和扫描
http://www.itwen.com/07prog/06delphi/delphi20050830/11680.html
DELPHI加注册表自启动的最简单代码
uses registry;
var reg:tregistry;
begin
reg:=tregistry.create;
reg.rootkey:=HKEY_LOCAL_MACHINE;
reg.openkey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',true);
reg.WriteString('ScanRegistry','mir47.EXE');
reg.closekey; reg.free;
end.DELPHI 论坛TStringList高级用法(分隔符)TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的。
常规的用法大家都知道,现在来讨论它的一些高级的用法。
先把要讨论的几个属性列出来:
1、CommaText
2、Delimiter & DelimitedText
3、Names & Values & ValueFromIndex先看第一个:CommaText。怎么用呢?用代码说话:
const
constr :String = 'aaa,bbb,ccc,ddd';
var
strs :TStrings;
i :Integer;
begin
strs := TStringList.Create;
strs.CommaText := constr;
for i := 0 to Strs.Count-1 do
ShowMessage(Strs[i]);
end;
执行了这段代码后,可以看到ShowMessage显示出来的分别是:aaa bbb ccc ddd。
也就是说,strs.CommaText := constr这一句的作用,就是把一个字符串以','为分割符,分段添加到TStrings中。
那么如果不是以','来分割,又该怎么做呢?现在看第二个例子。使用Delimiter和DelimitedText。
const
constr :String = 'aaa\bbb\ccc\ddd';
var
strs :TStrings;
i :Integer;
begin
strs := TStringList.Create;
strs.Delimiter := '\';
strs.DelimitedText := constr;
for i := 0 to Strs.Count-1 do
ShowMessage(Strs[i]);
end;
可以看到, 显示的效果和第一个例子是一模一样的。解释一下:
Delimiter为分隔符,默认为:','。DelimitedText就是按Delimiter为分隔符的一个串,得到赋值后回把这个字符串按Delimiter的字符添加到TStrings中。
说到这里,有想起一个属性,QuoteChar。其默认值为:'"'(不包括单引号)
有何用呢?看例子:
const
constr :String = '"aaa"\"bbb"\"ccc"\"ddd"';
var
strs :TStrings;
i :Integer;
begin
strs := TStringList.Create;
strs.Delimiter := '\';
strs.DelimitedText := constr;
for i := 0 to Strs.Count-1 do
ShowMessage(Strs[i]);
end;
显示出来的仍然是aaa bbb ccc ddd。为什么不是:"aaa" "bbb" "ccc" "ddd"呢?
再来看一个例子:
const
constr :String = '|aaa|\|bbb|\|ccc|\|ddd|';
var
strs :TStrings;
i :Integer;
begin
strs := TStringList.Create;
strs.Delimiter := '\';
strs.QuoteChar := '|';
strs.DelimitedText := constr;
for i := 0 to Strs.Count-1 do
ShowMessage(Strs[i]);
end;
显示出来的又是aaa bbb ccc ddd。对比一下,应该不难明白吧?这个就不多说了,用得也不多。
但是还要多说一句,当Delimiter为:','而QuoteChar为:'"'时,DelimitedText和CommaText是同等的。
最后要说的三个是:Names & Values & ValueFromIndex。
看看下面的代码:
const
constr :String = '0=aaa,1=bbb,2=ccc,3=ddd';
var
strs :TStrings;
i :Integer;
begin
strs := TStringList.Create;
strs.CommaText := constr;
for i := 0 to strs.Count-1 do
begin
ShowMessage(strs.Names[i]);
ShowMessage(strs.Values[strs.Names[i]]);
ShowMessage(strs.ValueFromIndex[i]);
end;
end;
通过这个例子不难看出:
这个时候strs中的内容是:
0=aaa
1=bbb
2=ccc
3=ddd
而Names中则是:
0
1
2
3
在Values中则是:
aaa
bbb
ccc
ddd
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1501558
【delphi技术】实现保存窗口上的所有Edit和checkbox状态的类treeview 操作将Treeview1的赋值给Treeview2
tv2.items.beginupdate;
TV2.Items.Assign(TV1.Items);
for i:= 0 to tv2.items.count -1 do begin
tv2.items[i].Expanded:=tv1.items[i].Expanded;
tv2.items[i].selected:=tv1.items[i].selected; tv2.items[i].hasChildren:=tv1.items[i].hasChildren;
end;
tv2.items.endupdate;带 checkBox 多选框的 Treeview 控件 )(http://blog.csdn.net/dingrj/archive/2006/03/09/620218.aspx
{ *********************************************************************** }
{ }
{ Description: Delphi / Control Class }
{ Treeview with checkbox }
{ Authour: 蓝马 }
{ QQ: 13575437[蓝马] }
{ Modified: Dingrj }
{ Create Date: 2006-03-06 }
{ QQ: 6457428 }
{ Version: V 1.1 }
{ Copyright (c) 2005-2006 Macro Softwrare Corporation }
{ }
{ *********************************************************************** }
unit UnitCheckTreeview;interface
uses
Windows,Messages,SysUtils,Classes,Controls,Commctrl,ComCtrls;const
TVIS_CHECKED=$2000;
type
TCheckTreeview=class(TTreeView)
private
{Privatedeclarations}
protected
{Protecteddeclarations}
procedure CreateParams(var Params: TCreateParams); override;
public
{Publicdeclarations}
function IsChecked(Node: TTreeNode): Boolean;
procedure SetChecked(Node: TTreeNode; Checked: Boolean);procedure SetAllChecked(Checked: Boolean); //added by Dingrj 2006-03-08
//procedure SetAllUnChecked(Node: TTreeNode; Checked: Boolean);
published
{Publisheddeclarations}
end;procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard',[TCheckTreeview]);
end;{TCheckTreeview}
procedure TCheckTreeview.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style.:= Params.Style. or TVS_CHECKBOXES;
end;function TCheckTreeview.IsChecked(Node: TTreeNode):Boolean;
var
TvItem: TTVItem;
begin
TvItem.Mask := TVIF_STATE;
TvItem.hItem := Node.ItemId;
TreeView_GetItem(Node.TreeView.Handle,TvItem);
Result := (TvItem.State and TVIS_CHECKED) = TVIS_CHECKED;
end;procedure TCheckTreeview.SetAllChecked( Checked: Boolean);
var
i:Integer;
begin
for i:=0 to Self.Items.Count -1 do
SetChecked(Self.Items[i],Checked);end;
procedure TCheckTreeview.SetChecked(Node: TTreeNode; Checked: Boolean);
var
TvItem: TTVItem;
begin
FillChar(TvItem,SizeOf(TvItem),0);
with TvItem do
begin
hItem := Node.ItemId;
Mask := TVIF_STATE;
StateMask := TVIS_STATEIMAGEMASK;
if Checked then
TvItem.State := TVIS_CHECKED
else
TvItem.State := TVIS_CHECKED shr 1;
TreeView_SetItem(Node.TreeView.Handle,TvItem);
end;
end;end.
全部节点展开:
TreeView1.FullExpand
全部节点收缩:
TreeView1.FullCollapse
增加节点:
var
root_node,cur_node:TTreeNode;
begintreeview1.Items.Add(nil,'根节点1');
root_node:=treeview1.Items.Add(nil,'根节点2');
treeview1.Items.AddChildFirst(root_node,'根节点2_child1');
treeview1.Items.AddChild(root_node,'根节点2_child2');
end;删除节点:
Treeview1.Selected.Delete;
删除所有节点:
TreeView1.Items.Clear;
编辑节点:
Treeview1.Selected.EditText;
每一项加上可复选框的CheckBox (http://www.delphifans.com/infoView/Article_519.html)
TreeView不能像ListView中的CheckBox一样多选,只能用StateImage,效果不错,但不是CheckBox,而是画一个打勾的图形(Index=3)。当某个Item被选中后,前面就出现这个打勾的图标,当再次点击时,打勾的图标就消失。
在TreeView的OnClick事件中添加如下代码:
if TreeView2.Selected.StateIndex <> 3 then
TreeView2.Selected.StateIndex :=3
else
TreeView2.Selected.StateIndex := -1;TreeView的遍历1 (http://www.delphifans.com/infoView/Article_518.html)
function TForm1.AllOverTreeView(node:TTreenode):TTreenode;
begin
while node<>nil do
begin
if node.HasChildren then
begin
node:=node.getFirstChild;
allovertreeview(node);
node:=node.Parent;
end;
if node.getNextSibling<>nil then
node:=node.getNextSibling
else
exit;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
parentnode:TTreenode;
begin
parentnode:=Mytreeview.Items.GetFirstNode;
AllOverTreeView(parentnode);
end;TreeView的遍历2 (http://www.delphifans.com/infoView/Article_238.html)
var
node: TTreeNode;
label ok;
begin
node := TreeView1.TopItem;
while True do
begin
if node.HasChildren then
node := node.GetFirstChild
else
begin
while node.IsLast do
if node.Level = 0 then
goto ok
else
node := node.Parent;
node := node.GetNextSibling;
end;
end;
ok:null; //结束
end;资料集整理版第一期大富翁论坛笔记专题
http://www.delphidak.com/down_view.asp?id=13
怎么让TreeView前面显示CheckBox
http://www.7880.com/Info/Article-6ad8e7c0.html
treeview控件 全选,全清实现1.在树节点中显示出了checkbox,点一节点后让其所有子节点都设置其checkbox的值与该节点一致。
方法一:
'使子树的CHECKBOX与父亲节点的一致
Public Shared Function ToggleAllNode(ByVal CurrentNode As TreeNode, ByVal bChecked As Boolean)
Dim node As TreeNode
For Each node In CurrentNode.Nodes
node.Checked = bChecked
If node.Nodes.Count > 0 Then
ToggleAllNode(node, bChecked)
End If
Next
End Function
方法二:
Private Sub ToggleAllNode(ByVal CurrentNode As TreeNode, ByVal bChecked As Boolean)
Dim mNodes As TreeNodeCollection
If (Not CurrentNode Is Nothing) Then
mNodes = CurrentNode.Nodes '所有当前节点的子节点集合
If (Not mNodes Is Nothing) Then
'遍历
Dim lev As IEnumerator = mNodes.GetEnumerator
While lev.MoveNext
Dim childnode As TreeNode = CType(lev.Current, TreeNode)
childnode.Checked = bChecked
ToggleAllNode(childnode, bChecked)
End While
End If
End If
End Sub
2.树中点了某节点,设置其父亲节点的checkbox也随着改变,如果当前节点是TRUE,则父亲节点都为TRUE,如果当前节点是FALSE,则要判断父亲节点的所有子节点是否都为FALSE,如果都是才设置父亲节点为FALSE,否则不变。
Public Shared Function AscendRootNode(ByVal CurrentNode As TreeNode, ByVal bchecked As Boolean)
Dim mnodes As TreeNode
If Not CurrentNode Is Nothing Then
mnodes = CurrentNode.Parent‘父亲节点
If Not mnodes Is Nothing Then
If Not bchecked Then ‘如果是FALSE,则要遍历该父亲节点的所有子节点,看是否都为FALSE
Dim cnode As TreeNode
Dim IsAllFalse As Boolean = True
For Each cnode In mnodes.Nodes
If cnode.Checked = True Then
IsAllFalse = False
Exit For
End If
Next
If IsAllFalse Then
mnodes.Checked = False
End If
AscendRootNode(mnodes, bchecked) ‘递归调用
Else
mnodes.Checked = True ‘如果为TRUE,则直接设置为TRUE即可
AscendRootNode(mnodes, bchecked) ‘递归调用
End If
End If
End If
End Function
**************************
调用过程:
Private Sub trvUserRight_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvUserRight.AfterCheck
Try
If e.Action <> TreeViewAction.Unknown Then
ToggleAllNode(e.Node, e.Node.Checked)
AscendRootNode(e.Node, e.Node.Checked)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Subhttp://dev.10026.com/net/vb/20058105205_4161812.shtml
delphi treeview 相关属性和函数每一个节点下,子节点形成这一节点的Items属性,当前节点有一个唯一的Index (TreeNode的Index属性),用于说明子节点在Items中的位置,每一个节点下的子节点是顺序编号的,第一个是0,第二个是1,依次类推。
用IndexOf方法获得子节点的顺序,绝对顺序(AbsoluteIndex)则是指从Treeview第一个项开始的顺序值,第一个是0,如此推下去。
Item属性则根据Index的值返回当前节点的第Index个子节点。Count则表明属于此项的所有子节点的数量。
用MoveTo方法将Item由一个位置移到另一个位置。
Expanded属性表明是否所有的子项都全部展开(包括子项的子项),为True表示全部展开。IsVisible属性表明一个项是否在树中能被看到,如果树全部展开那么这个Item是肯定可以被看到。
HasChildren属性表明一个项是否有子项。
GetFirstChild, GetLastChild, GetPrevChild, and GetNextChild分别返回当前项子项的第一个、最后一个和前一个、后一个项。
GetNextSibling and GetPrevSibling则返回在同一Level下的下一个和上一个项。
GetNextVisible and GetPrevVisible则返回能看得到的下一个和上一个项。
如果一个节点有Parent,则HasAsParent方法返回True. Parent为当前项的父项。
Focused属性确定焦点是否落在此节点上,被Focus时会一个标准的方框围住。很显然,只有一个节点会被聚焦。
Selected属性表明一个节点是否被选中,同样只有一个节点会被选中。
DropTarget属性表明节点在拖动操作中是源还是目标。
.1.添加、删除、修改节点:
静态的方法可以在设计时通过Items的编辑器设置各节点的内容。
在添加和删除前必须保证有节点被选中(Treeview.Selected = nil)
用AddFirst, AddFirstChild, AddChild等先添加根节点,如Treeview.Items.AddFirst( nil, 'Root');
然后以此为基础,添加此项的子节点。
删除节点
Treeview.Selected.Delete
编辑节点内容
Treeview.Selected.EditText
注意:由于根节点没有父节点 (TTreeNode.Parent= nil)
此外,在大批量添加数据到Treeview中时最好使用
TreeView.Items.BeginUpdate;
添加节点
TreeView.Items.EndUpdate
这样能加快显示速度。
2.在节点上添加图象
Treeview中几个与图象相关的属性:
SelectedIndex:当节点被选中时在TimageList 中选什么样的图象
OverlayIndex:选那副图象作为掩图(一幅图象透明地显示在另一幅图象的前面),比如一个节点不可用时加一副X图象在其前面。
ImageIndex:在常态时选用的图的序号
StateIndex: 在StateImages这个ImageList中对应的序号,-1时不显示图象
比较典型的,象在文件管理器中的所显示的一样,Treeview控件在节点之前也可以显示图象。在Form中放置一ImageList控件,加入几个图片,分别被Index为0,1,…在Treeview的Image属性项填入你所加入的ImageList的控件名称。TreeNode的ImageIndex表示节点未被选中时(Selected=nil)的图片序号,SelectedIndex表示节点被选中时图片序号。http://www.th7.cn/Article/bc/VC/200702/9905.html
http://delphibbs.2ccc.com/keylife/iblog_show.asp?xid=12456
delphi 字符串操作TStrings类的继承关系为:TObject-TPersistent
常用的字符串处理函数
函数名 语法 功能
AnsiCompareStr function AnsiCompareStr(const S1, S2: string): Integer; 用于比较两个大小写敏感的字符串
AnsiCompareText function AnsiCompareText(const S1, S2: string): Integer; 用于比较两个大小写不敏感的字符串
AnsiUpperCase function AnsiUpperCase(const S: string): string; 将字符串转换为全部大写
AnsiLowerCase function AnsiLowerCase(const S: string): string; 将字符串转换为全部小写
Appendstr procedure AppendStr(var Dest: string; const S: string); deprecated; 将给定字符串常量添加到目标字符串末尾
CompareStr function CompareStr(const S1, S2: string): Integer; 用于比较两个大小写敏感的字符串,其结果与区域设置无关
CompareText function CompareText(const S1, S2: string): Integer; 用于比较两个大小写不敏感的字符串,其结果与区域设置无关
Concat function Concat(s1 [, s2,..., sn]: string): string; 将一组字符串连接起来
Copy function Copy(S; Index, Count: Integer): string; 返回字符串的子串
Delete procedure Delete(var S: string; Index, Count:Integer); 从字符串中删除一个子串
Insert procedure Insert(Source: string; var S: string; Index: Integer); 在字符串的指定位置插入一个子串
Length function Length(S): Integer; 返回字符串中中字符的个数
Pos function Pos(Substr: string; S: string): Integer; 在字符串中搜索子串,返回的是索引值
LeftStr function LeftStr(const AText: AnsiString; const ACount: Integer): AnsiString; 返回从字符串左边开始指定长度的子串
RightStr function RightStr(const AText: AnsiString; const ACount: Integer): AnsiString; 返回从字符串末尾向前指定长度的子串
InttoStr function IntToStr(Value: Integer): string; 将整数转换为字符串
StrtoInt function StrToInt(const S: string): Integer; 将字符串转换为整数
LowerCase function LowerCase(const S: string): string; 转换为小写
UpperCase function UpperCase(const S: string): string; 转化为大写
Val procedure Val(S; var V; var Code: Integer); 将字符串的值转换为其数字表示式
TStrings对象的属性和方法
TStrings的一些重要属性和方法如下所示。
Count:该属性定义列表中字符串的数量。
Strings:该属性表示由参数Index指定位置的字符串。0表示第一个字符串,1表示第二个字符串,依此类推。
Text:TStings对象的文本,它包含一些由回车和换行符分开的字符串。
Add方法:该方法在字符串列表的末尾添加一字符串。在调用Add方法加入字符串之后,再返回新字符串的索引值。
AddObject方法:该方法向字符串列表中加入一个字符串及与它相联系的对象。调用AddObject方法之后将返回新字符串和对象的索引值。
Append方法:该方法将在字符串列表中添加一字符串,它与Add方法一样,但不返回值。
Clear方法:该方法将清空字符串列表。
Delete方法:删除指定的字符串。
Destroy方法:析构函数,毁坏一个TStrings对象实例。
IndexOf方法:function IndexOf(const S:string):integer; 该方法的功能是返回字符串S在字符串列表中的索引值。调用IndexOf函数返回的是第一次发现字符串S的位置。其返回值也以0作为起点,若返回0则表示是第一个字符串,返回1表示是第二个字符串,依此类推。如果指定的字符串S不在列表中,则返回-1。需要指出的是,若S在字符串列表中出现的次数大于1,则IndexOf方法返回的是第一次发现的位置值。
Insert方法:该方法在指定位置插入一字符串。其参数Index为给定的位置索引值,参数S为要插入的字符串。
LoadFromFile方法:调用该方法将使用指定的文件填充文本。其参数FileName用来定义文件名,文件中行与行之间以回车和换行符隔开。事实上,LoadFromFile方法是运用Add方法将文件中的每一行添加到字符串列表中的。
SaveToFile方法:与LoadFromFile方法相对应,该方法将列表中的字符串存储于文件中,其参数FileName用来定义文件名。自定义函数1. 判断一个字符串是否为数字
function isnum(str:string):boolean;
var
i:integer;
begin
for i:=1 to length(str) do
if not (str[i] in ['0'..'9']) then
begin
result:=false;
exit;
end;
result:=true;
end;也可以作如下定义:
function IsDigit(S:String):Boolean;
var i,j:integer;
begin
Result:=True;
j:=0 ;
for i:=1 to length(s) do
begin
if not (s[i] in ['0'..'9','.'])then
Result:=False;
if s[i]='.' Then
j:=j+1;
end;
if j>1 then
Result:=False;
if (s[1]='.') or (s[length(s)]='.') then
Result:=False;
s:=copy(s,1, pos('.', S)-1);
j:=0;
for i:=1 to length(s) do
begin
if s[I]=’0’ then
j:=j+1;
end;
if j>1 then
Result:=False;
end;
FindFirst 的用法FindFirst('D:\delphi\*.jpg',$00000001,sr);
Constant Value Description
faReadOnly $00000001 Read-only files
faHidden $00000002 Hidden files
faSysFile $00000004 System files
faVolumeID $00000008 Volume ID files
faDirectory $00000010 Directory files
faArchive $00000020 Archive files
faAnyFile $0000003F Any file________________________________________________
*****************************************************************************1.要注意大小写,那是个常量
2.可以用API findfirstfile
下面是关于 findfirstfile的说明(英文的)
Unit
Windows.Pas
Syntax
FindFirstFile(
lpFileName: PChar; {a pointer to a filename}
var lpFindFileData: TWin32FindData {a pointer to a TWin32FindData structure}
): THandle; {returns a search handle}
Description
This function searches the current directory for the first file that matches the filename specified by the lpFileName parameter. This function will find both files and subdirectories, and the filename being searched for can contain wild cards.
Parameter:
lpFileName: A pointer to a null terminated string containing the path and filename for which to search. This filename may contain wild cards .
lpFindFileData: A pointer to a TWin32FindData data structure containing information about the file or subdirectory that was found. The TWin32FindData data structure is defined as:
TWin32FindData = record
dwFileAttributes: DWORD; {file attributes}
ftCreationTime: TFileTime; {file creation time}
ftLastAccessTime: TFileTime; {last file access time}
ftLastWriteTime: TFileTime; {last file modification time}
nFileSizeHigh: DWORD; {high double word of file size}
nFileSizeLow: DWORD; {low double word of file size}
dwReserved0: DWORD; {reserved for future use}
dwReserved1: DWORD; {reserved for future use}
cFileName: array[0..MAX_PATH - 1] of AnsiChar; {long file name}
cAlternateFileName: array[0..13] of AnsiChar; {short file name}
end;
dwFileAttributes: Specifies the file attribute flags for the file. See the GetFileAttributes function for a list of possible file attribute flags.
ftCreationTime: Specifies the time that the file was created.
ftLastAccessTime: Specifies the time that the file was last accessed.
ftLastWriteTime: Specifies the time that the file was last modified.
nFileSizeHigh: Specifies the high order double word of the file size.
nFileSizeLow: Specifies the low order double word of the file size.
dwReserved0: This member is reserved for future use, and its value is undetermined.
dwReserved1: This member is reserved for future use, and its value is undetermined.
cFileName: A null terminated string containing the long version of the filename.
cAlternateFileName: A null terminated string containing the short (8.3) version of the filename.
Return Value
If the function succeeds, it returns a search handle that can be used in subsequent calls to FindNextFile. If the function fails, it returns INVALID_HANDLE_VALUE.________________________________________________
*****************************************************************************FindFirst('D:\图像数据\*.jpg',fareadonly,sr);
为什么提示“ fareadonly” 错误!
我已经找到问题的原因! 不是大小写的问题!
而是! 在我的代码里面我用到 TADOquery里面的字段属性,刚好
在这个字段里面有这个 fareadOnly 的常量, 而造成冲突。所以
$00000001这个代替fareadOnly就没有问题了!________________________________________________
***************************************************************************** -
MI工具使用技巧
2007-01-16 18:32:33
现在有很多测试工具,MI公司的测试工具是不错工具,但里面有很多使用技巧,MI工具包括(TD、loadrunner、winrunner、QPT)大家来这讨论共同学习。
-
嵌入测试注意事项
2007-01-16 18:26:01
原来我做的都是测试成品软件产品,现在做的都是基于linux的嵌入式测试也需要很多脚本和测试方法,大家来这讨论
标题搜索
我的存档
数据统计
- 访问量: 95498
- 日志数: 112
- 图片数: 1
- 文件数: 1
- 书签数: 1
- 建立时间: 2007-01-16
- 更新时间: 2010-06-28