Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stand alone unit 1

Status
Not open for further replies.

rcloutie

Programmer
May 26, 2005
164
CA
Hi there,

Is it possible to build a stand alone unit?
A kind of Procedure Main()...

Thanks
 
you can create a unit that contains a procedure that can be called from any other unit that contains the procedural unit in its uses clause.

Does that help?

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 

Single EXE - No GUI

1.Start program;
2.Copy some files;
3.Shell to another program;
4.Wait for termination;
5.Copy back modified files;
6.End program;

 
sounds like a service application; sorry I haven't ever developed one, but in researching one of my apps, I looked into it.

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
The DPF file is, in fact, a unit. For form-based window applications, its job is to create the main form (and other autocreated forms) and call Application.Run.

For console applications, you can put any code you want after the 'begin'.

Try File | New | Other | Console Application.

As for your protocol, you could copy the files and then wait for their timestamp to change.

To launch another program and wait for it to finish, you would want something like:
Code:
           if not Windows.CreateProcess(nil, PChar('"' + ThisEXEName + '" ' + Arguments), nil, nil,
               True, DETACHED_PROCESS or CREATE_SUSPENDED, nil, StartupDirPointer, ThisStartupInfo, ThisProcessInformation) then
           begin
               raise Exception.Create('Unable to run ' + EXEName + ': ' + IntToStr(Windows.GetLastError));
           end;

           ThisProcessHandle := ThisProcessInformation.hProcess;
           try
               ResumeThread(ThisProcessInformation.hThread);
               if TimeOutSeconds > 0 then
                   ThisTimeOut := Now + (TimeOutSeconds / (24 * 60 * 60))
               else
                   ThisTimeOut := 0;                       //  quiet the compiler warning
               repeat
                   Application.ProcessMessages;
                   Sleep(500);
                   Windows.GetExitCodeProcess(ThisProcessHandle, ThisCode);

               until (ThisCode <> STILL_ACTIVE) or ((TimeOutSeconds > 0) and (ThisTimeout < Now));

               if ThisCode = STILL_ACTIVE then
                   raise ERunTimeOutError.Create('Timed-out waiting for ' + EXEName + ' to finish', ThisProcessHandle);

           finally
               Windows.CloseHandle(ThisProcessHandle);
           end;

Cheers
 
Hi all,

First, thank you all.
Here's what I've done (and it works well):

1. Create a new standard application;
2. Add a new unit (which includes management code);
3. Call a unit's public method from the dpr;

----------------------------------------------------
program AppLocal;
uses
Forms,
UApp in 'UApp.pas',
UWait in 'UWait.pas' {frmWait};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TfrmWait, frmWait);
UApp.AppLocal(Application.Handle);
Application.Run;
end.
----------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top