• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

reformated or better way of doing this bit of code

would it be possable for sumone to recode this bit of code to make it work right? its not working for me I want to block a person that trys to talk when sumone else is my code below is for that.

the problem is  if lowercase(MainServer.Socket.Connections[i].Name) = lowercase(dat[0]) then when I add it it dont work can sumone recode it so it will work?

[code]
if com = 'SetMic' then
        try
          for i := 0 to MainServer.Socket.ActiveConnections - 1 do
          begin
            if lowercase(MainServer.Socket.Connections[i].Room) = lowercase(dat[1]) then
            if lowercase(MainServer.Socket.Connections[i].Name) = lowercase(dat[0]) then // I added this to pick username up
            begin
            if OnAir = True then
            begin
             MainServer.Socket.Connections[i].SendText(
                 CodeStr('šMicAlreadyUsedœ' + dat[0] + 'œ' + dat[1] + 'œ'));
            end
            else
            begin
              MainServer.Socket.Connections[i].SendText(
                CodeStr('šSetMicœ' + dat[0] + 'œ' + dat[1] + 'œ'));
                OnAir := True;

              if lowercase(MainServer.Socket.Connections[i].Name) =
                lowercase(dat[0]) then
                MainServer.Socket.Connections[i].Speak := True;
            end;
            end;
          end;
        except
      end;
[/code]

Thank you
0
fiveuk
Asked:
fiveuk
  • 6
  • 4
1 Solution
 
ginsonicCommented:
you get an error or just don't enter into this if statement ?

Have you try to debug (F5 and after that with F8) and to see what app return for lowercase(MainServer.Socket.Connections[i].Name) and for lowercase(dat[0]) ?
0
 
fiveukAuthor Commented:
none of my f keys work :( but I no it has sumthing to do with

            if lowercase(MainServer.Socket.Connections[i].Name) = lowercase(dat[0]) then

statment can you help?
0
 
fiveukAuthor Commented:
ok here my code

      if com = 'SetMic' then
        try
          for i := 0 to MainServer.Socket.ActiveConnections - 1 do
          begin
          if MainServer.Socket.Connections[i] <> nil then
          if (lowercase(MainServer.Socket.Connections[i].Name) = lowercase(dat[0])) or
             (lowercase(MainServer.Socket.Connections[i].Room) = lowercase(dat[1])) then
          begin
          MainServer.Socket.Connections[i].SendText(
                CodeStr('šSetMicœ' + dat[0] + 'œ' + dat[1] + 'œ'));
                OnAir := True;

              if lowercase(MainServer.Socket.Connections[i].Name) =
                lowercase(dat[0]) then
                MainServer.Socket.Connections[i].Speak := True;

          end
          else
          if OnAir = True then
             MainServer.Socket.Connections[i].SendText(
                 CodeStr('šMicAlreadyUsedœ' + dat[0] + 'œ' + dat[1] + 'œ'));
             end;
        except
      end;

Basicly I want to call the OnAir tree if sumone is on the mic allready but when I put the code at the start it dont work. can you maybe tel me the problem allso I can not debug as none of my FKeys work :( need new keybored
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ginsonicCommented:
It's hard to help because I don't know the structure of your dat. I supose that the .Name is a string;

Please select the row at design time

if MainServer.Socket.Connections[i] <> nil then

and then press F5. The line will color in red.

At runtime the app will stop here when the condition "if com = 'SetMic' then"  will be accepted.

With F8 run line by line and see if will enter in

 if (lowercase(MainServer.Socket.Connections[i].Name) = lowercase(dat[0])) or
             (lowercase(MainServer.Socket.Connections[i].Room) = lowercase(dat[1])) then
          begin

In same time you can add to watches nexts:

MainServer.Socket.Connections[i].Name
dat[0]
MainServer.Socket.Connections[i].Room
dat[1]

Just select the text and use Ctrl+F5 ( at design time ). You will see the values for these.

See the results. Maybe the name isn't the same with dat[0] all the time.
0
 
fiveukAuthor Commented:
dat[0] = is user that is mic and is allways

and

dat[1] is the room that the user is in.

like I says before I dont have any F keys as my keybored dont work so good.
0
 
ginsonicCommented:
Let me understand. You have a keyboard without function keys? from F1 to F12 or more?
0
 
ginsonicCommented:
You can test without function keys. just click on the band before the selected line and a red line will appear.

In RUN menu you have "Add watch" and "Step over".
0
 
fiveukAuthor Commented:
ok ty I did that but I dont see what it can do am not very good at debuging
0
 
ginsonicCommented:
if you have click the band and the red line appear (on design time) then the program will stop when run it and you can read the variables from inside.

I suggest here:
" if MainServer.Socket.Connections[i] <> nil then "

Before run you can select from RUN menu the Add watch option. Do this four time and add each line from nexts:

MainServer.Socket.Connections[i].Name
dat[0]
MainServer.Socket.Connections[i].Room
dat[1]

Have you do this? If you run now your application will stop before your wrong !? if statement. Here:

"if MainServer.Socket.Connections[i] <> nil then"

If yes then is OK.

When stop you will can read in watches list ( somewhere on left ) the values for the four variable. You can compare if are OK and if is what you expect.

To jump line by line and o see how these will be change use "Step next" from Run menu. If the application will enter if then is OK, if not will know whay now. You will know the values for conditions and will see what is wrong.

You will can see if Name is <> by Dat[0]and .....

If wish to continue your aplication just select Run and the application will continue untill will enter again inside

"if MainServer.Socket.Connections[i] <> nil then".

Without using this kind of debuging is very hard to find the errors.

You must run step by step and to detect the problem.

I wish you luck!



0
 
ginsonicCommented:
Step next... I think that is Step over.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now