Pass a variable to a procedure

Dear experts,

I have searching for hours on the internet to solve my problem.
But no luck!. I hope someone on EE can help me to solve my problem. I really need your help I can't solve it on my own.

I have made a Telnet-programm. The user can enter an IPaddress and Portnumber (in the editboxes) to connect to a server.

The Ipadres and the Portnumber entered in the editboxes are stored in 2 variables:

  ConnectHostName: string;
  ConnectPortNum: integer;

The problem is with the ConnectPortNum, how can i pass the
variable ConnectPortNum to this line in the procedure MakeConnect:

    pServAddr := getservbyname('telnet', 'tcp');    <=====
  if pServAddr <> nil then
          begin
            if deb then
            begin
              Log('Remote Service Info.:');
              Log('    Name: ' + PChar(pServAddr^.s_name));
              Log('    Port: ' + Format('%d', [ntohs           (pServAddr^.s_port)]));

            end;
            usPort := pServAddr^.s_port;
            RemoteAddr.sin_family := AF_INET;
            RemoteAddr.sin_addr.s_addr := ina.s_addr;
            RemoteAddr.sin_port := usPort;


   I have searched for the syntax on internet:

    PServAddr := ( service,  protocol )

   Does anyone know how I can pass the ConnectPorNum
   to the MakeConnect-procedure?

 Greetings,

Peter Kiers




LVL 1
peterkiersAsked:
Who is Participating?
 
peterkiersAuthor Commented:
I get an Access Violation:

pServAddr := getservbyname(pchar(ConnectPortNum),Nil);

P.
0
 
peterkiersAuthor Commented:
I found the answer.

Thank you very much for your help.

Gr,

Peter Kiers
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
diniludCommented:
i think you selected a wrong answer.
is it working properly.
if not please re open the question
0
 
diniludCommented:
function GetProtoNoAsString( ProtoNo : Integer):String;
var FProto:PProtoEnt;
begin
  FProto := getprotobynumber(ProtoNo);

  if FProto = NIL then
  begin
   ShowMessage(IntToStr(ProtoNo) + ' not available!');
   exit;
  end;

  Result := StrPas(FProto^.p_name);
end;
0
 
diniludCommented:
getservbyport
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.