Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if then else 1

Status
Not open for further replies.

Bamben

Programmer
Jul 22, 2009
70
IT
I have been working all day and now it is 3:38 AM and still I am faced by the very problem I tried to get around at first.

Let me try to explain:

I have built a program to call a phone line, some times the call drops so I have made a procedure which checks if the call is active or not.

//this procedure is broken XXX
procedure TMainForm.xCheck1;//this is suppost to check if call is active (but instead it always restarts the call)
Begin
if (CallPack[1].State = csActive) then
L1.Caption := 'ACTIVE'
else
if (CallPack[1].active = False) then
L1.Caption := 'X';
xCall1;//restart call
end;
//this procedure is broken XXX

There must be some thing wrong with my procedure because it always re-starts the call regardless of weather it is active or not (it will always jump to 'else')

I know that my procedure is set out wrong because; While the call is connecting it goes through the xConnecting1 procedure and this procedure repeats until the call is ether active or dropped.

procedure TMainForm.xConnecting1;//waits to connect
begin
CC := 0;
repeat
xConnectionCount1;
ACTIONL.Caption := 'Connecting Call 1';
Delay(300);
xConnectionCount1;
ACTIONL.Caption := 'Connecting Call 1.';
Delay(300);
xConnectionCount1;
ACTIONL.Caption := 'Connecting Call 1..';
Delay(300);
xConnectionCount1;
ACTIONL.Caption := 'Connecting Call 1...';
Delay(300);
until (CallPack[1].State = csActive) or (CallPack[1].active = false);
end;


I am STILL unsure of how to construct conditional procedures even after reading everything (and I mean EVERY THING) that I could find on delphi!

seriously this is the only thing in my code now that doesn't work (seen as I have dropped referring to the whole array at once lol I can get it working on a test program but not this perticular one lol)

this code almost works, and I am sure that it is my mistake with the construction of the argument in the xCheck1 procedure that is wrong! else why would the call be allowed to continue after the xConnecting1 procedure wich would continually repeat (if not csActive or dropped) were it not for the xConnectionCount1 procedure that hangs up the call if the CC count gets to 50 so I know that by the time the xCheck1 is done the call is ether active or dropped!!!

procedure TMainForm.xConnectionCount1;//if the call takes too long to connect ...hang up!
begin
CC := CC +1;
if CC = 50 then
SimpleSip1.EndCall(CallPack[1]);
end;

So my xCheck1 must be wrong other wise it wouldnt always re-call!

You get me? lol
 
first if you look at the procedure line by line
Code:
Begin
  if (CallPack[1].State = csActive) then L1.Caption := 'ACTIVE'
  else
  if (CallPack[1].active = False) then L1.Caption := 'X';

  xCall1;
end;
you will see xCall1 is outside of the if/then statement and is being called regardless.

you need to put multiple lines in a begin/end like so
Code:
Begin
  if (CallPack[1].State = csActive) then
    L1.Caption := 'ACTIVE'
  else
    if (CallPack[1].active = False) then
    begin
      L1.Caption := 'X';
      xCall1;
    end;
end;

also this is a neater way to perform xConnecting1
Code:
repeat
  xConnectionCount1;
  ACTIONL.Caption := 'Connecting Call 1';
  Delay(300);
  ACTIONL.Caption := ACTIONL.Caption +'.';
  until
    (CallPack[1].State = csActive) or (CallPack[1].active = false);

Aaron
 
You have taught me a valuable lesson!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top