[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] Delphi: Exposing properties of private members
Glenn Williamson wrote:
>
> Hey All,
>
> I'm writing a class which (among other things) maintains a TCP/IP
> connection to a server machine. Like so:
>
> //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-//
> type
> TOrc = class(TObject)
> private
> FSocket: TClientSocket;
>
> public
> property Host: string read blah write blah;
> property Port: Integer read blah write blah;
> end;
> //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-//
>
> .. where the public Host property maps directly to the FSocket.Host
> property, and likewise for the Port property. I was wondering if there was
> a way to directly expose these as public properties rather than having to
> write GetHost, SetHost, GetPort and SetPort routines.
>
> i.e.
>
> property Host: string read FSocket.Host write FSocket.Host;
>
> .. but that doesn't work.
I remember doing something of the sort where u could make a property
which calls a function when it is written to, and another when it is
read.
so something like:
private
getHost: Fsocket.Host;
procedure setHost(Value: string);
published
property Host: string read getHost write setHost;
procedure classtype.setHost(Value: string);
begin
FSocket.Host=Value;
end;
sure, this involves write a set??? procedure, but its not that much
work. Actually, thats probably what u didn't want to do.
from the manual (delphi 4), the access specifier (the name after the
read or write statement) is ``the name of a field or method declared in
the same class as the property or in an ancestor class''. So from this,
I would assume u would either have to write functions as mentioned, or
inherit the TClientSocket class (which may be a better way to do it
anyway - inheritance is ur friend)
hope this make a bit of sense and helps.
--
vik@nospam.progsoc.org
<http://www.progsoc.org/~vik>
PGP: <http://www.progsoc.org/~vik/pgp.txt>
If you think education is expensive, try ignorance.
-- Derek Bok, president of Harvard
-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.