Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Enable / Disable button from a server! Posted by Development on 7 Nov 2004 at 9:03 AM
I have a problem with my program I need to disable a button when a user is online and using mic button is this possable to do?

I have my client saying the username of the person on mic but I like it to disable everyone elses talk button, but not the person that is talking

here my username code maybe it can be used to help?


This is the event when the user press's button it sends name to server along with talk command.

procedure TForm1.XiButton2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
waveIn.close();
ClientSocket1.Socket.SendText('PRESSSPEAK');
SendData('SPNSENDON',LoginName);
end;


Then when server gets info it replys with following

if command = 'SPNSENDON' then
begin
username := GetByTab(egg,1);
Broadcast(Socket,'SPEAKNAME'+chr(9)+username);
end;


then client runs the speakname code this adds name to label.

if GetByTab(egg,0) = 'SPEAKNAME' then
begin
i := 0;
Label3.Caption := GetByTab(egg,i)+' Is on microphone ..';

repeat
inc(i);

if GetByTab(egg,i) <> '' then
Label3.Caption := GetByTab(egg,i)+' Is on microphone ..';
until
GetByTab(egg,i) = '';
end;


now is there anyway I can user it so it will disable everyone elses button other then the person that is talking?

SORRY FOR ANYBAD SPELLING!

Slewis
Report
Re: Enable / Disable button from a server! Posted by netgert on 8 Nov 2004 at 6:32 AM
: I have a problem with my program I need to disable a button when a user is online and using mic button is this possable to do?
:
: I have my client saying the username of the person on mic but I like it to disable everyone elses talk button, but not the person that is talking
:
: here my username code maybe it can be used to help?
:
:
: 
: This is the event when the user press's button it sends name to server along with talk command.
: 
: procedure TForm1.XiButton2MouseDown(Sender: TObject; Button: TMouseButton;
:   Shift: TShiftState; X, Y: Integer);
: begin
: waveIn.close();
: ClientSocket1.Socket.SendText('PRESSSPEAK');
: SendData('SPNSENDON',LoginName);
: end;
: 

:
: Then when server gets info it replys with following
:
:
: if command = 'SPNSENDON' then
: begin
: username := GetByTab(egg,1);
: Broadcast(Socket,'SPEAKNAME'+chr(9)+username);
: end;
: 

:
: then client runs the speakname code this adds name to label.
:
:
: if GetByTab(egg,0) = 'SPEAKNAME' then
: begin
: i := 0;
: Label3.Caption := GetByTab(egg,i)+' Is on microphone ..';
: 
: repeat
: inc(i);
: 
: if GetByTab(egg,i) <> '' then
: Label3.Caption := GetByTab(egg,i)+' Is on microphone ..';
: until
: GetByTab(egg,i) = '';
: end;
: 

:
: now is there anyway I can user it so it will disable everyone elses button other then the person that is talking?
:
: SORRY FOR ANYBAD SPELLING!
:
: Slewis
:
the code in red should be this:
if GetByTab(egg,0) = 'SPEAKNAME' then
begin
XiButton2.Enabled := GetByTab(egg,1) = LoginName; // Enabled only if currently talking username is what the user is logged in as

Label3.Caption := GetByTab(egg,1)+' Is on microphone ..'; // In the above code i don't see that server sends more than two tab-separated parameters but i can see that the currently talking user is always the second parameter (index 1)
end;

hope this helps

NetGert[/italic]


Report
Re: Enable / Disable button from a server! Posted by Development on 8 Nov 2004 at 8:41 PM
Still did not work here my full client and server commands maybe you can see were I am going worng????

Client TALK BUTTON COMMANDS
---------------------------

// BUTTON ON HOLD DOWN!

procedure TForm1.XiButton2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
waveIn.close();
SendData('SPNSENDON',LoginName); // Sends command to server to enable voice allso sends username!
ClientSocket1.Socket.SendText('TBOFF'); // sends command to server to disable all other clients talk button
ClientSocket1.Socket.SendText('PRESSSPEAK'); // sends command to let server know user is talking
end;


// BUTTON ON UP!

procedure TForm1.XiButton2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
waveIn.close();
ClientSocket1.Socket.SendText('TBON'); // sends command to server to enable all other clients talk button
ClientSocket1.Socket.SendText('SPNSENDOFF'); // Sends command to server to disenable voice
ClientSocket1.Socket.SendText('PRESSLISTEN'); // sends command to let server know user no longer is talking
end;


CLIENT TCLIENTSOCKET INFO!
--------------------------

if egg = 'LISTEN' then
begin
c_rb_listen.Checked := True; // disables talk mode and enables listen mode
end;

if egg = 'SPEAK' then
begin
c_rb_speak.Checked := True; // enables talk mode
end;

if GetByTab(egg,0) = 'SPEAKNAME' then
begin
i := 0;
XiButton2.Enabled := GetByTab(egg,i) = LoginName;
Label3.Caption := GetByTab(egg,i)+' Is on microphone ..'; // adds username that is talking

repeat
inc(i);

if GetByTab(egg,0) <> '' then
XiButton2.Enabled := GetByTab(egg,1) = LoginName;
Label3.Caption := GetByTab(egg,1)+' Is on microphone ..'; // adds username that is talking
until
GetByTab(egg,i) = '';
end;

if egg = 'NONAME' then
begin
ClientSocket1.Socket.SendText('SETBAR'); // sends to server to reset all other clients progressbars(volume)
Label3.Caption := 'Microphone FREE!';
end;


SERVER COMMANDS!

if command = 'PRESSSPEAK' then // Sends out command to enable talk mode
begin
SendData(socket,'SPEAK');
end;

if command = 'PRESSLISTEN' then
begin
SendData(socket,'LISTEN'); // Sends out command to enable listen mode
end;

if command = 'TBON' then
begin
Broadcast(Socket,'TBUTTONON'); // Disables talk button on all clients
end;

if command = 'TBOFF' then
begin
Broadcast(Socket,'TBUTTONOFF'); // Enables talk button on all clients
end;

if command = 'SPNSENDON' then
begin
username := GetByTab(egg,1);
Broadcast(Socket,'SPEAKNAME'+chr(9)+username); // Sends the user name of the person talking to all clients
end;

if command = 'SPNSENDOFF' then
begin
Broadcast(Socket,'NONAME'); // Removes the username  when person stops talking
end;

if command = 'SETBAR' then
begin
Broadcast(Socket,'SETBARS'); // Resets all clients volume bars
end;


hope it helps you find the error!
Slewis

Report
Re: Enable / Disable button from a server! Posted by netgert on 9 Nov 2004 at 6:51 AM
it is not working because previously u posted a different code, without TBOFF an TBON. see modifications (in red, comments in blue)
: Still did not work here my full client and server commands maybe you can see were I am going worng????
:
:
: Client TALK BUTTON COMMANDS
: ---------------------------
: 
: // BUTTON ON HOLD DOWN!
: 
: procedure TForm1.XiButton2MouseDown(Sender: TObject; Button: TMouseButton;
:   Shift: TShiftState; X, Y: Integer);
: begin
: waveIn.close();
: SendData('SPNSENDON',LoginName); // Sends command to server to enable voice allso sends username!
: ClientSocket1.Socket.SendText('TBOFF'); // sends command to server to disable all other clients talk button
: ClientSocket1.Socket.SendText('PRESSSPEAK'); // sends command to let server know user is talking
: end;
: 

:
:
: // BUTTON ON UP!
: 
: procedure TForm1.XiButton2MouseUp(Sender: TObject; Button: TMouseButton;
:   Shift: TShiftState; X, Y: Integer);
: begin
: waveIn.close();
: ClientSocket1.Socket.SendText('TBON'); // sends command to server to enable all other clients talk button
: ClientSocket1.Socket.SendText('SPNSENDOFF'); // Sends command to server to disenable voice
: ClientSocket1.Socket.SendText('PRESSLISTEN'); // sends command to let server know user no longer is talking
: end;
: 

:
:
: CLIENT TCLIENTSOCKET INFO!
: --------------------------
: 
: if egg = 'LISTEN' then
: begin
: c_rb_listen.Checked := True; // disables talk mode and enables listen mode
: end;
: 
: if egg = 'SPEAK' then
: begin
: c_rb_speak.Checked := True; // enables talk mode
: end;
: 
: if GetByTab(egg,0) = 'SPEAKNAME' then
: begin
: i := 0;
remove this line:
: XiButton2.Enabled := GetByTab(egg,i) = LoginName;
: Label3.Caption := GetByTab(egg,i)+' Is on microphone ..'; // adds username that is talking
: 
: repeat
: inc(i);
: 
: if GetByTab(egg,0) <> '' then
remove this line:
: XiButton2.Enabled := GetByTab(egg,1) = LoginName;
didn't get ur idea of looping i. anyway this seems fishy as server always sends 1 username, not like 10 or so (because u disable other's buttons and disable them to speak - also the server code doesnt handle multiple users speaking at once
: Label3.Caption := GetByTab(egg,i)+' Is on microphone ..'; // adds username that is talking
: until
: GetByTab(egg,i) = '';
: end;
: 
: if egg = 'NONAME' then
: begin
: ClientSocket1.Socket.SendText('SETBAR'); // sends to server to reset all other clients progressbars(volume)
: Label3.Caption := 'Microphone FREE!';
: end;
the problem is that you are not handling button on-off messages sent by the server
if egg = 'TBUTTONOFF' then XiButton2.Enabled := False;
if egg = 'TBUTTONON' then XiButton2.Enabled := True;
: 

:
:
: SERVER COMMANDS!
: 
: if command = 'PRESSSPEAK' then // Sends out command to enable talk mode
: begin
: SendData(socket,'SPEAK');
: end;
: 
: if command = 'PRESSLISTEN' then
: begin
: SendData(socket,'LISTEN'); // Sends out command to enable listen mode
: end;
: 
: if command = 'TBON' then
: begin
: Broadcast(Socket,'TBUTTONON'); // Disables talk button on all clients
: end;
: 
: if command = 'TBOFF' then
: begin
: Broadcast(Socket,'TBUTTONOFF'); // Enables talk button on all clients
: end;
: 
: if command = 'SPNSENDON' then
: begin
: username := GetByTab(egg,1);
: Broadcast(Socket,'SPEAKNAME'+chr(9)+username); // Sends the user name of the person talking to all clients
: end;
: 
: if command = 'SPNSENDOFF' then
: begin
: Broadcast(Socket,'NONAME'); // Removes the username  when person stops talking
: end;
: 
: if command = 'SETBAR' then
: begin
: Broadcast(Socket,'SETBARS'); // Resets all clients volume bars
: end;
: 

:
: hope it helps you find the error!
: Slewis
:
:


NetGert[/italic]


Report
Re: Enable / Disable button from a server! Posted by Development on 10 Nov 2004 at 2:22 PM
This message was edited by Development at 2004-11-10 15:18:10

Thanks to netgert for this code but I am still having a few problems with it I dont no were to say basicly it work on my local pc but once I move it to my server and tryed it when I presst the button it lock on me and I had to restart program so if any of you see the problem other just me :)

I think it maybe the fact that the username( (GetByTab(egg,0) ) is not working it proble trying to use everyones name as talker!

SERVER :

// START OF TALK BUTTON SERVER

if command = 'TBON' then
begin
Broadcast(Socket,'TBUTTONON');
end;

if command = 'TBOFF' then
begin
Broadcast(Socket,'TBUTTONOFF'+chr(9)+username);
end;

// END OF TALK BUTTON SERVER


CLIENT :

// START OF CLIENT TALK BUTTON

procedure TForm1.XiButton2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if lstMembers.Count = 1 then
begin
ShowMessage('Sorry! You need more users connected to voice server.'#13#10'Unless you really want to talk to your self?.');
Exit;
end
else
begin
waveIn.close();
SendData('SPNSENDON',LoginName);
ClientSocket1.Socket.SendText('TBOFF');
ClientSocket1.Socket.SendText('PRESSSPEAK');
bTalking := True;
end;
end;

procedure TForm1.XiButton2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
waveIn.close();
ClientSocket1.Socket.SendText('TBON');
ClientSocket1.Socket.SendText('SPNSENDOFF');
ClientSocket1.Socket.SendText('PRESSLISTEN');
bTalking := False;
end;

// END OF CLIENT TALK BUTTON


// START OF SOCKET TALK BUTTON

if egg = 'TBUTTONON' then
begin
XiButton2.Enabled := True;
end;

if (GetByTab(egg,0) = 'TBUTTONOFF') and (not bTalking) then
begin
XiButton2.Enabled := False;
end;

// END OF SOCKET TALK BUTTON




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.