Thanks for all,

Can I create an unique project that I'll be able to compile to run as service on Windows XP/2K, as a normal program on a Windows 98 and as a Daemon on Linux or will I need to have 3 distincts applications?

Regards

Fabrício



Fabrício F. Kammer

Burkhard Carstens escreveu:
Am Montag, 21. August 2006 21:51 schrieb Fabrício F. Kammer:
Hi all,

I'm writing an TCP server using synapse and I want that the
application runs as a console application to be comptible with linux
and windows systems.

I did the graphical applicatio using lazarus and running on windows,
but I don't know how to make a console application.

I'm doing like bellow:
- I created the new project (project menu-New project-Program);
- I put the code to create the TCP Sockects as I made on the
graphical application;
- I put on the initiallization section the code to create the socket;

But when I ran the project1.exe on a windows machine the program
start and close on next... the program don't be running and listening
on the specific tcp port informed by me.

Can anyone help me with this?

You can use TCustomApplication for this like:

program consoleserver;

uses classes;

type
  TMyApp = Class(TCustomApplication)
    procedure DoRun; override;
  end;

procedure TMyApp.DoRun;
begin
  {This method will be called in a loop until MyApp.terminated=true }
end;

begin
  MyApp:=TMyApp.Create(nil);
  MyApp.Initialize;
  //depending on your error handling style, you could also do this:
  //MyApp.StopOnException:=true;
  MyApp.run;
  MyApp.Free;
end.

Jou can override "Initialize" to, well, initialize stuff (creating instance of your server-component etc.)

Just beware of the TCustomApplication commandline parameter handling methods (HasOption and stuff). They do funny crap in some circumstances. Fix those or use GetOpts directly.



regards,
 Burkhard


_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to