Enable / Disable button from a server! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Enable / Disable button from a server!

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?

[code]

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;
[/code]

Then when server gets info it replys with following

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

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

[code]
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;
[/code]

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

Comments

  • netgertnetgert Posts: 331Member
    : 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?
    :
    : [code]
    :
    : 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;
    : [/code]
    :
    : Then when server gets info it replys with following
    :
    : [code]
    : if command = 'SPNSENDON' then
    : begin
    : username := GetByTab(egg,1);
    : Broadcast(Socket,'SPEAKNAME'+chr(9)+username);
    : end;
    : [/code]
    :
    : then client runs the speakname code this adds name to label.
    :
    [red]: [code]
    : 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;
    : [/code][/red]
    :
    : 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]red[/red] should be this:
    [code]
    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;
    [/code]
    hope this helps
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • DevelopmentDevelopment Posts: 222Member
    Still did not work here my full client and server commands maybe you can see were I am going worng????

    [code]
    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;
    [/code]

    [code]
    // 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;
    [/code]

    [code]
    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;
    [/code]

    [code]
    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;
    [/code]

    hope it helps you find the error!
    Slewis

  • netgertnetgert Posts: 331Member
    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????
    :
    : [code]
    : 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;
    : [/code]
    :
    : [code]
    : // 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;
    : [/code]
    :
    : [code]
    : 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;
    [blue]remove this line:[/blue]
    [red]: XiButton2.Enabled := GetByTab(egg,i) = LoginName;[/red]
    : Label3.Caption := GetByTab(egg,i)+' Is on microphone ..'; // adds username that is talking
    :
    : repeat
    : inc(i);
    :
    : if GetByTab(egg,0) <> '' then
    [blue]remove this line:[/blue]
    [red]: XiButton2.Enabled := GetByTab(egg,1) = LoginName;[/red]
    [blue]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[/blue]
    : Label3.Caption := GetByTab(egg,[red]i[/red])+' 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;
    [blue]the problem is that you are not handling button on-off messages sent by the server
    [red]if egg = 'TBUTTONOFF' then XiButton2.Enabled := False;
    if egg = 'TBUTTONON' then XiButton2.Enabled := True[/red];
    : [/code]
    :
    : [code]
    : 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;
    : [/code]
    :
    : hope it helps you find the error!
    : Slewis
    :
    :

    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • DevelopmentDevelopment Posts: 222Member
    [b][red]This message was edited by Development at 2004-11-10 15:18:10[/red][/b][hr]
    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 :

    [code]
    // 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
    [/code]

    CLIENT :

    [code]
    // 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
    [/code]

    [code]
    // 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
    [/code]
Sign In or Register to comment.