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

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




0
peterkiers
Asked:
peterkiers
  • 4
  • 2
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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