Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-02

My object function is overriding real function

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeremy Cowgar

Greetings.

I have a object that connects to a speech server, festival. In my object, I define a function called close. This must close the socket connection, which is done by the function close. Therefore, I am having a problem, because simply calling close with the sin and sout parameters results in an error because it is calling my objects close function which takes no parameters.

How can I call a function that is not part of my object, but has the same name as one of my object functions? Here is my simple code, for example:

function TFestival.Open(host : string; port : integer) : integer;
var
    h : THost;
    addr : TInetSockAddr;
begin
    h.NameLookup(host);
    if h.LastError  0 then
      begin
        Open := 1;
        Exit;
      end;
    addr.family := AF_INET;
    addr.port   := ShortHostToNet(port);
    addr.addr   := HostTonet(longint(h.IPAddress));
    sock := Socket(AF_INET, SOCK_STREAM, 0);
    if Not Connect(sock, addr, sin, sout) then
      begin
        Open := 2;
        Exit;
      end;
    rewrite(sout);
    reset(sin);
    Open := 1;
end;
procedure TFestival.Close();
begin
    close(sin);
    close(sout);
    Close := 0;
end;

I realize that I can simply rename my close procedure but I imagine that I will run into similar situations as I continue to use Free Pascal.

Thank you for your help,

Jeremy

Jon D. Sawyer
to Jeremy Cowgar

If the function you wish to call is apart of another unit you can call

i.g.:
 UnitName.Close(sin);
 UnitName.Close(sout);

** That may work from within the same unit but I'm not certain. **

Free pascal is great about name spaces and allowing you to specify which function you wish to call.

Jeremy Cowgar wrote 62 lines
Greetings. I have a object that connects to a speech server, festival. In my object, I define a function called close. This must close the socket connection, which is done by the function close. Therefore, I am having a problem, because simply calling close with the sin and sout parameters results in an error because it is calling my objects close function which takes no parameters. How can I call a function that is not part of my object, but has the same name as one of my object functions? Here is my simple code, for example: function TFestival.Open(host : string; port : integer) : integer; var h : THost; addr : TInetSockAddr; begin h.NameLookup(host); if h.LastError 0 then begin Open := 1; Exit; end; addr.family := AF_INET; addr.port := ShortHostToNet(port); addr.addr := HostTonet(longint(h.IPAddress)); sock := Socket(AF_INET, SOCK_STREAM, 0); if Not Connect(sock, addr, sin, sout) then begin Open := 2; Exit; end; rewrite(sout); reset(sin); Open := 1; end; procedure TFestival.Close(); begin close(sin); close(sout); Close := 0; end; I realize that I can simply rename my close procedure but I imagine that I will run into similar situations as I continue to use Free Pascal. Thank you for your help, Jeremy _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Matt Emson
to Jeremy Cowgar: Greetings. I have a object that connects to a speech server, festival. In my object, I…
Show quoted text 6 lines
I have a object that connects to a speech server, festival. In my object, I define a function called close. This must close the socket connection, which is done by the function close. Therefore, I am having a problem, because simply calling close with the sin and sout parameters results in an error because it is calling my objects close function which takes no parameters.

Simple answer, qualify the function or procedure with the unit name.

e.g.

   SocketFuncs.Close;

where 'SocketFuncs' contains the routine clashing with your other function.

Matt