[fpc-pascal]My object function is overriding real function

Jon D. Sawyer badquanta6384 at comcast.net
Thu Feb 19 03:26:02 CET 2004


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.


On Wed, 2004-02-18 at 20:50, Jeremy Cowgar wrote:
> 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  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list