How do I get these 2 programs to work together (ie have one call the other.)
Thought of using the first to call the external one but then thought it better to combine the 2 ????? Can't seem to get it working yet the second one works on it's own.
I have left some of the bits commented outas I was testing with these and will remove them when finished.
all ideas accepted.
***********************************
{First part of the program}
Program pinger1; {Checks for LAN IP before running main prog}
uses
Dos;
var
shell: string;
F: text;
s: string;
i: string;
Prog: string;
begin
begin
(* get path to command shell for environment *)
shell := GetEnv ('COMSPEC');
Exec (shell, '/C cls');
//Exec (shell, '/C ping -n 1, 127.0.0.1');
(* Parameter /C instructs the shell to run the command and terminate *)
Exec (shell, '/C ping -n 2, 127.0.0.1 > pingtest.txt');
Exec (shell, '/C cls');
end;
begin
assign (F, 'pingtest.txt');
reset (F);
i := '127.0.0.2';
while NOT eof (F) do
begin
readln (F, s);
s := (s);
if s >= i then
break
// write ('NOPE')
else
// write ('YEP');
//Exec (shell, '/C D:/My Documents/lapbak/steves tests/solautolapbak.exe');
begin
SolAutoLapBak03; {[B]it won't recognise this bit[/B]}
end;
end;
end;
//end.
{Second part of the program}
procedure SolAutoLapBak03;
{$mode delphi}
{.$mode objpas}
{$apptype gui}
uses
Windows,
SysUtils,
IsConnected,
dos,
Log;
const
PRODUCT = 'Soleco UK Ltd Lapbak';
VERSION = 'v0.3';
NETTEST_TID = 0;
NETTEST_VAL = 300 * 1000; // 300 seconds 5mins
DBLCHECK_TID = 1;
DBLCHECK_VAL = 600 * 1000; // 600 is 10mins
TOMMOROW_TID = 2;
TOMMOROW_VAL = 86400 * 1000; // 86400 is 24hrs
BACKUPCMD = '\\nt-lich4\lapbak\lapbak.bat';
// BACKUPCMD = '"c:\program files\lapbak\lapbak.bat"';
// BACKUPFOLDER = '"d:\my documents"';
CR = #13;
LF = #10;
CRLF = CR+LF;
var
ProgramName : string;
h : THandle;
BackupFolder : ansistring;
procedure DebugMsg(s : ansistring);
begin
MessageBox(0, PChar(s), PChar(ProgramName), MB_ICONERROR);
end;
procedure StartNetTestTimer;
begin
SetTimer(h, NETTEST_TID, NETTEST_VAL, nil);
end;
procedure StopNetTestTimer;
begin
KillTimer(h, NETTEST_TID);
end;
procedure StartDblCheckTimer;
begin
SetTimer(h, DBLCHECK_TID, DBLCHECK_VAL, nil);
end;
procedure StopDblCheckTimer;
begin
KillTimer(h, DBLCHECK_TID);
end;
procedure StartTommorowTimer;
begin
SetTimer(h, TOMMOROW_TID, TOMMOROW_VAL, nil);
end;
procedure StopTommorowTimer;
begin
KillTimer(h, TOMMOROW_TID);
end;
procedure ExecBackup;
begin
WriteLogFile('Exec Backup.. CMD: '+BACKUPCMD+' Folder: "'+BACKUPFOLDER+'"');
CloseLogFile;
Exec(BACKUPCMD,'"'+BACKUPFOLDER+'"');
OpenLogFile(BackupFolder+'\lapbak.log');
end;
function WndProc(Window: HWnd; Message, WParam, LParam: Longint): Longint; stdcall; export;
begin
case Message of
WM_TIMER :
begin
case wParam of
NETTEST_TID:
begin
if IsConnectedToInternet = INTERNET_CONNECTION_LAN then
begin
StopNetTestTimer;
WriteLogFile('Lan connection detected... waiting to retry...');
StartDblCheckTimer;
end;
end;
DBLCHECK_TID:
begin
if IsConnectedToInternet = INTERNET_CONNECTION_LAN then
begin
StopDblCheckTimer;
WritelogFile('Still Connected... starting backup.');
ExecBackup;
StartTommorowTimer;
end;
end;
TOMMOROW_TID:
begin
//a new day....
WriteLogFile('A new day..');
StopTommorowTimer;
StartNetTestTimer;
end;
end;
end;
WM_CREATE:
begin
//DebugMsg('WM_CREATE');
end;
wm_EraseBkgnd:
begin
Result := 1;
Exit;
end;
WM_DESTROY:
begin
PostQuitMessage(0);
end;
else begin
Result := DefWindowProc (Window, message, wParam, lParam) ;
Exit;
end;
end;
Result := 0;
end;
var
msg: TagMsg;
wndclass: TWndClass;
// ProgramName: string = 'contest';
begin
ProgramName := PRODUCT+' '+VERSION;
wndclass.hInstance := hInstance;
with wndclass do
begin
style := 0;
lpfnWndProc := @WndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hIcon := LoadIcon(0, IDI_APPLICATION);
hCursor := LoadCursor(0, IDC_ARROW);
hbrBackground := HBRUSH(GetStockObject(WHITE_BRUSH));
lpszMenuName := nil;
lpszClassName := PChar(ProgramName);
if Windows.RegisterClass(wndclass) = 0 then
begin
DebugMsg('Program requires Windows NT!');
Halt(0);
end;
h := CreateWindow(PChar(ProgramName), PChar(ProgramName),
WS_BORDER,
200, 200,
200, 200,
0, 0, hInstance, nil) ;
// ShowWindow(hwnd, System.CmdShow) ;
UpdateWindow(h);
BackupFolder := ParamStr(1);
if BackupFolder = '' then
begin
DebugMsg('FATAL! No Backup Folder specified!'+CRLF+'Please contact Jerome (jeboutillier@florette.com) 01543 250050');
Halt;
end;
OpenLogFile(BackupFolder+'\lapbak.log');
StartNetTestTimer;
while GetMessage(msg, 0, 0, 0) do begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
CloseLogFile;
Halt(msg.wParam);
end;
end;
end.