Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Apr : TCPServer & MSSQL & Threads (Newbie Question)

www.cryer.info
Managed Newsgroup Archive

TCPServer & MSSQL & Threads (Newbie Question)

Subject:TCPServer & MSSQL & Threads (Newbie Question)
Posted by:"Mark Moss" (markmo..@adelphia.net)
Date:Wed, 16 Apr 2008 19:55:48

Ladies / Gentlemen


        I am new to Thread Programming, so please bear with me.

        Below is Code from Chad Z. Hower, ( aka "Kudzu" ) book "Indy in
Depth" that is supposed to be Thread Safe.

        The Sleep(5000) is supposed to represent the SQL statements.

        What I need to know is the proper way to execute SQL code thru
components that are located on a DataModule and the proper way to declare
GlobalVariables so that they are unique to each Thread.


        Do I Declare the GlobalVariables in the interface section under a
Threadvar such as

var
  Form1: TForm1;

ThreadVar
   x : integer;

{-----------------------------------------------------------------------------------------------------------------}

        And do I have to Create the DataModule and all of the components on
it for each Thread.  If not what do I do?

        Any HELP that you can give me will be greatly appreciated.

Mark Moss


{-----------------------------------------------------------------------------------------------------------------}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer;

type
  TForm1 = class(TForm)
    IdTCPServer1: TIdTCPServer;
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
   i : integer;
begin

     with AThread.Connection do
         begin
              WriteLn('Hello. DB Server Ready.');
              i  :=  StrToIntDef(ReadLn, 0);
              Sleep(5000);
              WriteLn(IntToStr( i * 7 ));
              Disconnect;
         end;

end;

end.

{---------------------------------------------------------------------------------------------------------}

Replies:

www.cryer.info
Managed Newsgroup Archive