ورود

View Full Version : چگونه بدانیم که یک برنامه اجرا شده است یا نه



Keramatifar
پنج شنبه 28 خرداد 1383, 12:45 عصر
To do this,Create a new project and write following codes, so run the project and see the result in the same folder that there is a Program.log file in it.
at the same time,these codes can add in any pas file.if you do it then you must define the name of pas file under uses line on the project source.

-----------


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

const PrgLog : String[200] = 'Program.Log';

var
Form1: TForm1;
TXF : TextFile;

implementation

{$R *.DFM}

Procedure STOP;
begin //if Program.log file can not create
MessageDlg( PrgLog+' could not create', mtWarning, [mbOk], 0);
Halt;
end;

Procedure SaveDateTime( fn:String; Alan:String );
begin // write to Program.log file
if not FileExists( PrgLog ) then
begin
System.AssignFile(TXF, PrgLog );
{$I-}System.Rewrite(TXF);{$I+} if IOResult<>0 then STOP;
System.Writeln(TXF, Application.ExeName+' '+Application.Title );
System.Writeln(TXF, '' );
System.Writeln(TXF, '+ '+DateTimeToStr(Now) );
System.CloseFile(TXF);
end
else
begin
System.AssignFile(TXF, PrgLog );
{$I-}System.Append(TXF);{$I+} if IOResult<>0 then STOP;
System.Writeln(TXF, alan );
System.CloseFile(TXF);
end;
end;

initialization
begin // application is running
PrgLog := ExtractFileDir(Application.ExeName)+'\'+PrgLog;
SaveDateTime( PrgLog, '+ '+DateTimeToStr(Now) );
end;

finalization
begin // application is closing
SaveDateTime( PrgLog, '- '+DateTimeToStr(Now) );
end;

end.

JavanSoft
پنج شنبه 28 خرداد 1383, 20:09 عصر
ممنون از لصف شما و این نکاتی که ذکر می کنید
آیا بهتر نیست انها را در یک بحث بنام "نکته های برنامه نویسی دلفی " جمع اوری کنید

Keramatifar
جمعه 29 خرداد 1383, 12:50 عصر
انیم فکر خوبیه
متشکرم