Jump to content

@rturas

Members
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. @rturas

    Disable all controls on panel

    As my mother language is not english i might misunderstood your post. Please correct me if i am wrong: if i will put WaitFor into the thread, then i will not be in need to use Application.ProcessMessage?
  2. @rturas

    Disable all controls on panel

    Well, in my case it did work, WaitFor did not neglet Application.ProcessMessages. procedure TfrmPanel.btnWriteASCII_ShrtClick(Sender: TObject); var myStr: string; i: Integer; begin pnl3.Enabled := False; myStr := ''; try if fTCPClient.Connected then begin fTCPClient.IOHandler.WriteLn('set OutputType=ASCII_SHORT'); if fTCPClient.IOHandler.InputBufferIsEmpty then begin for i := 0 to 1 do myStr := myStr + fTCPClient.IOHandler.WaitFor(Char($0A), True, False, IndyTextEncoding_ASCII, 5000); end; end; finally begin mmo1.Lines.Add(myStr); Application. ProcessMessages; pnl3.Enabled := True; end; end; end; Anyway, i do not state, that it is a good solution. I use 5000 ms TimeOut for WaitFor, because i do not know exactly, when the second answer from the server comes (it should be within couple of seconds). First answer is only a feedback to my request, second one - confirmation that request is proccessed with/without errors.
  3. @rturas

    Disable all controls on panel

    Based on the answer of the Anders Melander i have added Application.ProcessMessages; right before pnl3.Enabled := True; Not sure if it is a good idea.
  4. @rturas

    Disable all controls on panel

    I see, thank you!
  5. @rturas

    Disable all controls on panel

    Hello, I want to disable all the controls that are on the specific panel (buttons, edits, etc.) while i read data from server. For that reason i use: TPanel.Enabled := False And reenable it after reading is finished. If i click on any disabled button while panel is disabled, its event is fired after the panel is reanabled. Is it normal behavior, or am i doing something wrong? My code looks like that: procedure TfrmPanel.FormShow(Sender: TObject); begin fTCPClient := TIdTCPClient.Create; fTCPClient.Host := IP; fTCPClient.Port := Port; try fTCPClient.Connect; except on E: Exception do //Handle exception end; end; procedure TfrmPanel.btnWriteASCII_ShrtClick(Sender: TObject); var myStr: string; i: Integer; begin pnl3.Enabled := False; myStr := ''; try if fTCPClient.Connected then begin fTCPClient.IOHandler.WriteLn('set OutputType=ASCII_SHORT'); if fTCPClient.IOHandler.InputBufferIsEmpty then begin for i := 0 to 1 do myStr := myStr + fTCPClient.IOHandler.WaitFor(Char($0A), True, False, IndyTextEncoding_ASCII, 5000); end; end; finally begin mmo1.Lines.Add(myStr); pnl3.Enabled := True; end; end; end;
  6. @rturas

    Indy TCP client

    Hello Remy, Thank you so much for the explanation. It is highly appreciated.
  7. @rturas

    Indy TCP client

    Hello, I am trying to create the app that sends a messages to the server and gets back an answer from it in a thread on the regular time intervals. Request contains 6 bytes, answer should be 65 bytes. My code looks like that: //TThread Constructor inherited Create(True); TCPClient := TIdTCPClient.Create; TCPClient.Host := AHost; TCPClient.Port := APort; TCPClient.ConnectTimeout := 5000; TCPClient.ReuseSocket := rsTrue; //TThread Execute procedure SetLength(wBuffer, 6); //Here i do write some bytes SetLength(rBuffer, 65); while not Terminated do begin try TCPClient.Connect; except on E: Exception do begin TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Exception: ' + e.Message); end); for i := 1 to 5 do begin if not Terminated then Sleep(1000); end; Continue; end; end; Reading := False; i := 1; while not Terminated do begin if not Reading then begin Reading := True; TCPClient.IOHandler.Write(wBuffer, 6, 0); end; try if Reading then begin if TCPClient.IOHandler.CheckForDataOnSource(100) then begin TCPClient.IOHandler.ReadBytes(rBuffer, 65, False); TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Buffer size: ' + IntToStr(TCPClient.IOHandler.InputBuffer.Size)); end); if not TCPClient.IOHandler.InputBufferIsEmpty then begin //I do some stuff here i := i +1; Reading := False; Sleep(1000); end; end; end; except on E: Exception do begin TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Reading exception: ' + e.Message); end); Sleep(1000); Continue; end; end; end; end; I do get only one line in the memo: Buffer size: 0 What am i doing wrong? How can i fix it? Thank you in advance.
×