请问如何在delphi中检测文件自身大小
请教各位xdjm,如何在delphi中检测文件自身大小,希望能讲详细点,谢谢!! 用FILESIZE函数吧,先随便指定个数LEN,编译后,得到真正的长度,然后再把LEN改为真正的长度,在程序中比较。 多谢caterpilla (惊涛) !! 给出DELPHI 源码 获得程序自己大小!~unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function FileSizeEx(const FileName: string): Int64;
var
Info: TWin32FindData;
Hnd: THandle;
begin
Result := -1;
Hnd := FindFirstFile(PChar(FileName), Info);
if (Hnd <> INVALID_HANDLE_VALUE) then
begin
Windows.FindClose(Hnd);
Int64Rec(Result).Lo := Info.nFileSizeLow;
Int64Rec(Result).Hi := Info.nFileSizeHigh;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EDIT1.Text:=Application.ExeName;
Edit2.Text:=IntToStr(FileSizeEx(Edit1.Text));
end;
end.
[ 本帖最后由 ww-jack 于 2006-11-26 19:31 编辑 ]
在主程序中完成检查
Application.Initialize;if if GesSelfSize()<> 379904 then Application.Terminate;
Application.CreateForm(TForm1, Form1);
Application.Run;
没有在实际编程实验,试一下吧,呵呵。 多谢了,有学习了一招。在次感谢ww-jack 多谢ww-jack和caterpilla (惊涛) 兄弟。
页:
[1]