procedure TForm1.Button1Click(Sender: TObject);
下面我该怎么调用上面的函数呢
下面我该怎么调用上面的函数呢
解决方案 »
- richEdit插入WORD里的表格会变形
- dll中 无法sendmessage 给主程序
- 如何用delphi把数据库中的内容导入Word
- 急 请问:如何写代码,远程备份SQLServer数据库?在线等
- 高分求助!我想在Delphi7用NMHTTP,但为何没有FastNet组件
- 我在自己的机子上写了段小程序,可是换个机子提示:database engine error
- 急!!!怎样才能在空的记录后面最加多条记录?
- 圖片的打印
- 嘻嘻嘻<<第一次亲密接触CSDN.HELP>>.HELP嘻嘻嘻嘻
- Delphi中使用Crystal Report怎么把它的设计器调出来?
- 看看这个错在哪里
- 这个代码上我赋值改赋点什么
定义在FormCreat事件 中,
Button事件是不能调用的,你应该将它拉出来,放在
private
或
public
{ Public declarati
均可:
单元代码:
unit Unit1;interfaceuses
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 }
function GetFileCount(srcPath, srcFileName: string): Integer;
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.GetFileCount(srcPath, srcFileName: string): Integer;
var FileRec: TSearchrec;
currPath: string;
begin
if srcPath[Length(srcPath)] <> '\' then srcPath := srcPath + '\';
currPath := srcPath + '*.*';
Result := 0;
if FindFirst(currPath, faAnyFile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) and
(FileRec.Name <> '.') and
(FileRec.Name <> '..') then
begin
Result := Result + GetFileCount(srcPath + FileRec.Name, srcFileName);
end
else
if AnsiCompareText(srcFileName, FileRec.Name) = 0 then
Result := Result + 1;
until FindNext(FileRec) <> 0;
end;procedure TForm1.Button1Click(Sender: TObject);
var n:integer;
begin
n:=GetFileCount('I:\', '1.txt');
showmessage('有'+inttostr(n)+'个同名文件');
end;end.
U盘的不同的目录,拷贝若干个1.txt文件。 就可以验证了。比如U盘是I:
procedure TForm1.Button1Click(Sender: TObject);
var n:integer;
begin
n:=GetFileCount('I:\', '1.txt');
showmessage('有'+inttostr(n)+'个同名文件');
end;