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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mystery code 1

Status
Not open for further replies.

Bamben

Programmer
Jul 22, 2009
70
IT
I am very confused about what is going on here but I have had a good look at it and a attempt to translate or decipher what is happening...

'i' counts the length of the AddPIN text

'b' is a var of the whole form. what's it doing at the end of this code?:

DTMF(copy(addPIN.text,i,1),b);

I think its telling the DTMF procedure to copy the AddPIN text (1 digit at a time) and...??? what is the 1 for? and b???

'j' start as 0 and counts until its less than 10x (multiplied by) the number specified in the SecondsBetweenPIN Text box. then it sleeps for 100 (milliseconds??.) after that, it adds 1 to 'j'

then it goes back to the start of the loop, it does this until 'i' reaches the length of the AddPIN text.


//***********************************************
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
b:integer;

procedure TForm1.DTMF(n:string;c:integer);
begin
if Assigned(CurrentCall) and CurrentCall.Active then
SimpleSip1.PlayWavFile(CurrentCall, AppPath+n+'.wav');
LOG('SEND: '+n);
end;


procedure TForm1.sendingPIN;
var i,j,b:integer;
begin
Log ('Now Sending PIN...');
for i:=1 to length(AddPIN.text) do
begin
DTMF(copy(addPIN.text,i,1),b);
j:=0;
while j<(10*StrToInt(SecondsBetweenPIN.Text)) do
begin
sleep(100);
application.ProcessMessages;
inc(j);
end;
end;
end;

//*************************************************

Ps: the reason I added the DTMF procedure is because i cant see how this procedure can do anything other than what its meant to do.

Could someone else have a go at deciphering this and perhaps correct me if I am wrong in my assumptions?
 
The code there appears to play wave files that are called 1.wav, 2.wav corresponding to the digits contained in the pin, and pausing a certain amount of time between each number. ie. it is a computer voice that reads a pin number out to the listener.
 
where do you see that it plays 2.wav?

at what point does the number 1 or 2 become the 'n' string in the procedure DTMF?

I don't see how the two procedures connect.
 
as griffyn said, the code takes the text from editbox addPIN
and sends each digit, with a pause of x seconds between them, set by the SecondsBetweenPIN editbox.
the 2 parameter of the DTMF procedure doesn't make sense as it is not used.

I rewrote the code to make it more clear:

Code:
var
   Form1: TForm1;

procedure Pause(Seconds : Integer);

var j : integer;

begin
 for j := 1 to Seconds * 10 do
  begin
   Sleep(100); // shorter sleep times keeps app responsive
   Application.ProcessMessages;
  end;
end;

procedure TForm1.DTMF(Digit : string);
begin
 if Assigned(CurrentCall) and CurrentCall.Active then
  SimpleSip1.PlayWavFile(CurrentCall, AppPath+n+'.wav');
 Log('SEND: '+n);
end;


procedure TForm1.SendPIN;

var i     :integer;
    Digit : string;

begin
 Log ('Now Sending PIN...');
 for i:=1 to length(AddPIN.text) do
  begin
   Digit := copy(addPIN.text,i,1)
   DTMF(Digit);
   Pause(StrToInt(SecondsBetweenPIN.Text));
  end;
end;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
small code correction:

SimpleSip1.PlayWavFile(CurrentCall, AppPath+n+'.wav');

should be :

SimpleSip1.PlayWavFile(CurrentCall, AppPath + Digit + '.wav');

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
AHHHHHH!!! I see I see I see :) so 'Digit' and 'n' are both strings and DTMF accepts the string of Digit and calls it 'n'.

wow I really don't like that style of code...its terrible!

So who ever wrote this original code is ether rrrreally good at compressing their code!? or just plain messy??

Thanks guys, this is really helping me to understand how data is juggled between procedures.

(for ... to ... do) this has got me really thinking!!!!
is this basically a way of telling a procedure to do some thing a certain number of times then stop? Because if it is then that's really cool! I have been learning how to stop a procedure after a condition is met by counting from 0 to 10 and that worked too!!! I am really starting to get this now, its quite enjoyable.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top