[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using sockets in a formless application

Posted on 2007-10-09
4
Medium Priority
?
474 Views
Last Modified: 2010-08-05
I want to write a formless aplication, but I need to use Socket such as TCLientSocket and TServerSocket, but the problem is that I dont know how to manage events like OnClientCOnnect, OnAccept, OnGetSocket, OnListen, OnRead OnClientRead, OnConnect, OnDisconnect, etc When I use forms I can do this:

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
//All my code here
end;

 But How can I do the same without forms?
0
Comment
Question by:manganzon
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 375 total points
ID: 20046587
well, i'm not an expert for Comsole-Apps, but i would try this way

a sceleton:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, ScktComp;

type TSocketMethodDispatcher = class(TObject)
     public
        procedure ClientRead(Sender: TObject;  Socket: TCustomWinSocket);
        //maybe more
end;

var
  vSocketMethodDispatcher : TSocketMethodDispatcher;
  vClientSocket : TClientSocket;

procedure TSocketMethodDispatcher.ClientRead(Sender: TObject;  Socket: TCustomWinSocket);
begin
  //Code Here
end;

begin
  vSocketMethodDispatcher := TSocketMethodDispatcher.Create;
  vClientSocket := TClientSocket.Create(nil);
  try
    vClientSocket.OnRead := vSocketMethodDispatcher.ClientRead;
  //more
  finally
    vClientSocket.Free;
    vSocketMethodDispatcher.Free;
  end;

end.

meikl ;-)
0
 
LVL 28

Expert Comment

by:2266180
ID: 20046805
formless doesn't mean console application :P you can have a windows applicaiton without forms with no problem. jsut remove all forms from a windows project and voila.

also, the nice delphi RAD way of doing this is using a datamodule :)
so, after you created teh windows applicaiton and removed the forms you do
File->New->Data Module
and you can drop any component on the data module and work with them as if they were on a form :)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 20047399
>formless doesn't mean console application :P
good point, ciuly ;-)
0
 
LVL 6

Expert Comment

by:den4b
ID: 20048139
kretzschmar, if you remove {$APPTYPE CONSOLE} from your program above - it will become a form-less AND console-less application ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question