Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

DIOCP 3 full download with example

Discussion in 'Delphi Components' started by N0body, Aug 6, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    [​IMG]

    Database operation is relatively simple, is divided into two parts, the first part of open SQL

    Code:
    procedure TfrmMain.btnOpenSQLClick(Sender: TObject);
    var
      lvJSonStream, lvRecvObject:TJsonStream;
      lvStream:TStream;
      lvData:AnsiString;
      l, j, x:Integer;
    begin
      lvJSonStream := TJsonStream.Create;
      try
        lvJSonStream.JSon := SO();
        lvJSonStream.JSon.I['cmdIndex'] := 1001;   //Open a SQL script, data acquisition
        lvJSonStream.Json.S['sql'] := mmoSQL.Lines.Text;
    
        FClientSocket.sendObject(lvJSonStream);
      finally
        lvJSonStream.Free;
      end;
    
      //Read data
      lvRecvObject := TJsonStream.Create;
      try
        FClientSocket.recvObject(lvRecvObject);
    
        if not lvRecvObject.getResult then
        begin
          raise Exception.Create(lvRecvObject.getResultMsg);
        end;
    
        SetLength(lvData, lvRecvObject.Stream.Size);
        lvRecvObject.Stream.Position := 0;
        lvRecvObject.Stream.ReadBuffer(lvData[1], lvRecvObject.Stream.Size);
    
        cdsMain.XMLData := lvData;
      finally
         lvRecvObject.Free;
      end;
    end;
    
    Processing server in ClientContext

    Code:
    procedure TClientContext.dataReceived(const pvDataObject:TObject);
    var
      lvJsonStream:TJSonStream;
      lvFile:String;
      lvCmdIndex:Cardinal;
      lvXMLData, lvEncodeData:AnsiString;
      lvSQL:String;
    begin
      lvJsonStream := TJSonStream(pvDataObject);
    
      lvCmdIndex := lvJsonStream.JSon.I['cmdIndex'];
    
      //Echo test
      if lvCmdIndex= 1000 then
      begin
        InterHIDE-THANKSedIncrement(TesterINfo.__RecvTimes);
        //Write back data
        writeObject(lvJsonStream);
      end else if lvCmdIndex = 1001 then
      begin  //According to SQL, a data acquisition, in Stream
        try
          lvSQL := lvJsonStream.Json.S['sql'];
    
          lvXMLData := dmMain.CDSProvider.QueryXMLData(lvSQL);
    
          lvJsonStream.Clear();
          lvJsonStream.Stream.WriteBuffer(lvXMLData[1], Length(lvXMLData));
          lvJsonStream.setResult(True);
        except
          on e:Exception do
          begin
            lvJsonStream.Clear();
            lvJsonStream.setResult(False);
            lvJsonStream.setResultMsg(e.Message);
          end;
        end;
        
        //Write back data
        writeObject(lvJsonStream);
    

    Save data to a very nice DLL
    The client:

    Code:
    procedure TfrmMain.btnPostClick(Sender: TObject);
    var
      lvJSonStream, lvRecvObject:TJsonStream;
      lvStream:TStream;
      lvData:AnsiString;
      l, j, x:Integer;
    begin
      if cdsMain.State in [dsInsert, dsEdit] then cdsMain.Post;
      
      if cdsMain.ChangeCount = 0 then
      begin
        ShowMessage('Without any modification!');
        exit;
      end;
      lvJSonStream := TJsonStream.Create;
      try
        lvJSonStream.JSon := SO();
        lvJSonStream.JSon.I['cmdIndex'] := 1002;   //Open a SQL script, data acquisition
    
        //Package amendment record
        with TCDSOperatorWrapper.createCDSEncode do
        begin
          setTableINfo(PAnsiChar(AnsiString(edtUpdateTable.Text)), PAnsiChar(AnsiString(edtKeyFields.Text)));
          setData(cdsMain.Data, cdsMain.Delta);
          //Execute code
          Execute;
          lvData := getPackageData;
        end;
    
        mmoData.Clear;
        mmoData.Lines.Add(lvData);
    
        lvJSonStream.Stream.Write(lvData[1], Length(lvData));
    
        FClientSocket.sendObject(lvJSonStream);
      finally
        lvJSonStream.Free;
      end;
    
      //Read data
      lvRecvObject := TJsonStream.Create;
      try
        FClientSocket.recvObject(lvRecvObject);
    
        if not lvRecvObject.getResult then
        begin
          raise Exception.Create(lvRecvObject.getResultMsg);
        end else
        begin
          ShowMessage('Successfully saved!');
        end;
      finally
         lvRecvObject.Free;
      end;
    
      cdsMain.MergeChangeLog();
    
    end;
    
    The server:

    Code:
    if lvCmdIndex = 1002 then  //Save the data to the familiar
      begin
        try
          lvJsonStream.Stream.Position := 0;
          SetLength(lvEncodeData, lvJSonStream.Stream.Size);
          lvJsonStream.Stream.ReadBuffer(lvEnCodeData[1], lvJSonStream.Stream.Size);
    
          dmMain.ExecuteApplyUpdate(lvEncodeData);
    
          lvJsonStream.Clear();
          lvJsonStream.setResult(True);
        except
          on e:Exception do
          begin
            lvJsonStream.Clear();
            lvJsonStream.setResult(False);
            lvJsonStream.setResultMsg(e.Message);
          end;
        end;
        
        //Write back data
        writeObject(lvJsonStream);
      end
    

    Hidden Content:
    **Hidden Content: You must click 'Like' before you can see the hidden data contained here.**
     
  2. alexza
    Offline

    alexza DF Member

    RE:

    thanks
     
  3. delphi_sk
    Offline

    delphi_sk DF Junior

    RE:

    Thank :rolleyes:
     
  4. getjan
    Online

    getjan Guest

    RE:

    thanks:rolleyes:
     
  5. rezox
    Online

    rezox Guest

    RE:

    DIOCP ?..what is this?
     
  6. snowmansoft
    Offline

    snowmansoft DF Member

    RE:

    thks. A great work.
     
  7. yhlee304
    Offline

    yhlee304 DF Expert DF Gold User

    RE:

    thank you for all :)
     
  8. Lgogo
    Online

    LgogoLgogo is a Featured Member DF Expert DF Donator

    RE:

    Thanks
     
  9. saneh
    Offline

    saneh DF Member

    RE:

    Thank you.
     
  10. brionna
    Online

    brionna Guest

    thanks
     
  11. audy018
    Offline

    audy018 DF Junior

    RE:

    [font=Verdana, Arial, sans-serif]Thanks[/font]
     
  12. yedrath
    Offline

    yedrath DF Junior

    RE:

    Thanks
     
  13. ssdd123456
    Offline

    ssdd123456 DF Member

    RE:

    thanks
     
  14. BadBlue
    Offline

    BadBlue DF Senior

    RE:

    Thanks
     
  15. mystic2lb
    Online

    mystic2lb Guest

  16. rusmin
    Online

    rusmin Guest

    RE:

    Thanks
     
  17. kilmos
    Offline

    kilmos DF Junior

    RE:

    Thanks
     
  18. programistait
    Offline

    programistait DF Junior

    RE:

    thx a lot
     
  19. Yiyo
    Offline

    Yiyo DF Senior

    RE:

    Thanks
     
  20. pairojr
    Offline

    pairojr DF Junior

    RE:

    [font=Verdana, Arial, sans-serif]thank you [/font]
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block