Article View: borland.public.csharpbuilder.ide.general
Article #138Re: Accessing the component "Name" property
From: Francois PIETTE [ICS - MidWare]
Date: Fri, 04 Aug 2006 18:18
Date: Fri, 04 Aug 2006 18:18
50 lines
3175 bytes
3175 bytes
>>> Basically you can't, all .NET components work the same way.
>>
>> I don't believe I can't access the "(Name)" property by code within the
>> component class. I will ask on MS newsgroups...
>
> Sure, you could also check the help file, there is no name property
> for any .net component. The property editor makes this up based purely
> on the name of the variable it is assigned to in the initialization
> (hence the parentheses around the name).
OK, I've found where this property is located.
Actually it is a property of the ISite interface which is available thru
Component.Site property.
The Site property has a value only when the component is dropped on a form
(owned by a container). So to use that property, you can write the code
below:
[Browsable(false)]
public string Name {
get { if (Site == null)
return FName;
else
return Site.Name;
}
set { FName = value;
if (Site != null)
Site.Name = FName;
}
}
protected string FName;
This code define a non browsable property (that is which doesn't appears in
the object inspector and is mapped to the Site.Name property when Site is
assigned. If not, it is mapped to a protected string member.
This implementation perfectly fit my need: When a component is dropped on a
form, it has a value for Site.Name which is available thru the Name property
I created. When the component is created at runtime, it has a the property
Name which is mapped to the adequate storage.
I could enhance a little bit the implementation by overriding set_Site in
order to not loose the Name property value when the component is included
within a container. But this is not necessary for any use I have.
Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
Technical Details
Message-ID:
<44d38fd7@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.musoftware.de!news.code-werk.net!open-news-network.org!news.soft-gems.net!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mailReferences:
<44d223ec@newsgroups.borland.com> <m1p14y1fhmc$.dlg@dlg.marcrohloff.com> <44d2eafa@newsgroups.borland.com> <sfgbn1yxwdzf$.dlg@dlg.marcrohloff.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 165859,b80637074c138806 X-Google-Attributes: gid165859,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> Newsgroups: borland.public.csharpbuilder.ide.general References: <44d223ec@newsgroups.borland.com> <m1p14y1fhmc$.dlg@dlg.marcrohloff.com> <44d2eafa@newsgroups.borland.com> <sfgbn1yxwdzf$.dlg@dlg.marcrohloff.com> Subject: Re: Accessing the component "Name" property Date: Fri, 4 Aug 2006 20:18:34 +0200 Lines: 53 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.246.223.104 Message-ID: <44d38fd7@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1154715607 81.246.223.104 (4 Aug 2006 11:20:07 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.musoftware.de!news.code-werk.net!open-news-network.org!news.soft-gems.net!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail