Solved

IDTCPCLIENT SEND MESSAGE TO IDTCPSERVER TO INSERT ROW IN DATABASE.

Posted on 2006-07-15
3
612 Views
Last Modified: 2010-04-04
I HAVE 10 PROGRAM CLIENT CONNECTED IN MY PROGRAM SERVER, I DID THAT USING TIDTCPSERVER AND TIDTCPCLIENT. WORKS GOOD.

IN THE SERVER I HAVE OBJECT TQUERY TO UPDATE OR INSERT WHEN SOME CLIENT CONNECT OR DISCONNECT.

THE PROBLEM IS WHEN MORE THEN ONE CLIENT SEND MESSAGE TO SERVER FOR INSERT OR UPDATE AT THE SAME TIME.
I GOT ERROR IN MY TQUERY.
0
Comment
Question by:rafaelrgl
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 17115817
you will need to use a separate tquery and transaction for each client.
I would recommend creating them dynamicaly for each client when they connect
Otherwise you wii get thread errors as more than 1 client tries to use the tquery etc.

eg. inside the OnConnect event make an object that has your tquery inside it

type
    TClientSpecificData = class(TObject)
  private
      function GetCurrentProgressPercent: integer;
  public
      clientquery: TQuery;
      Constructor Create; override
      Destructor Destroy; override;
  end;

        { TClientSpecificData }

constructor TClientSpecificData.CreateWithSettings(ID_: string);
    begin
        Inherited Create;
        ClientQuery := TQuery.Create(nil);
// set query parameters here
    end;

destructor TClientSpecificData.Destroy;
    begin
        ClientQuery.Free;
        inherited;
    end;


procedure TfServerMain.IdTCPServer1Connect(AContext: TIdContext);
    begin
        AContext.Data := TClientSpecificData.Create;
    end;

procedure TfServerMain.IdTCPServer1Disconnect(AContext: TIdContext);
    begin
        if assigned(AContext.Data) then
        begin
            (AContext.Data as TClientSpecificData).Free;
            AContext.Data := nil;
        end;
    end;

procedure TfServerMain.IdTCPServer1Execute(AContext: TIdContext);
    var
        i: integer;
        S, S2: string;
        InCmd: string;
    begin
          InCmd := AContext.Connection.IOHandler.ReadLn;
// just an example
          (AContext.Data as TClientSpecificData).ClientQuery.SQL.Text := InCmd;
          (AContext.Data as TClientSpecificData).Open;
    end;
           
This is how I'd do it with the latest indy 10.
You can se how to do it with indy 9, or 10.0.52 on my demos page
http://sourceforge.net/projects/internetdemos

0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17115835
WHY YOU USE THIS LINE LIKE THIS: AContext.Connection.IOHandler.ReadLn; AND I USE THAT: AThread.Connection.ReadLn;

WHAT IS IOHANDLER?
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17117962
it depends on your version of Indy, with Indy 9 (the default) you just use .Connection.ReadLn
with Indy 10, there were some changes, and you use IOHandler
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now