1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

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,Freeware, Open Source' started by AdminDF, Aug 6, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan 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 Verified Member Downloader DF Payment Group

    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