PC Review


Reply
Thread Tools Rate Thread

Changing DisplayNames of my properties using PropertyGrid component, how ??

 
 
Tugrul HELVACI
Guest
Posts: n/a
 
      4th Dec 2006

I'm using Delphi 2006 and I have a class defination like this:

TPerson = class
fPersonName : String;
fPersonSurName : String;
fPersonAge : Integer;
published
property PersonName : String read fPersonName write fPersonName;
property PersonSurname : String read fPersonSurname write fPersonSurname;
property PersonAge : Integer read fPersonAge write fPersonAge;
end;

and i want to display my class instance using PropertyGrid,so...

var
mPerson : TPerson;
begin
mPerson := TPerson.Create;
mPerson.PersonName := 'Tugrul';
mPerson.PersonSurname := 'HELVACI';
mPerson.PersonAge := 31;
PropertyGrid1.SelectedObject := mPerson;
end;

at the above code i can see my class instance in the property grid.
But i want to change property display names in the propertygrid component.
Because of these, i was searching on the net and i found PropertyDescriptor
abstract class
and ICustomTypeConverter interface.

i implemented theese classes following:

TArrayOfAttribute = array of Attribute;
TMyDescriptor = class(PropertyDescriptor)
private
base : PropertyDescriptor;
fName: String;

function GetName : String;
function GetDisplayName : String;
function GetIsReadOnly : Boolean;
function GetComponentType : &Type;
function GetPropertyType : &Type;

function GetCustomNames(baseName : String) : String; // my custom names
getter function
public
constructor Create(baseP : PropertyDescriptor; filter :
TArrayOfAttribute); overload; virtual;
constructor Create(baseP : PropertyDescriptor); overload; virtual;

function CanResetValue(comp : TObject) : Boolean;
function GetValue(comp : TObject) : TObject;

procedure ResetValue(comp : TObject);
procedure SetValue(comp : TObject; Value : TObject);
function ShouldSerializeValue(comp : TObject) : Boolean;


property Name : String read GetName;
property DisplayName : String read GetDisplayName;
property IsReadOnly : Boolean read GetIsReadOnly;
property ComponentType : &Type read GetComponentType;
property PropertyType : &Type read GetPropertyType;
end;

TMyClass = class(TInterfacedObject, ICustomTypeDescriptor)
public
function GetProperties(filter : TArrayOfAttribute) :
PropertyDescriptorCollection; overload;
function GetAttributes : AttributeCollection;
function GetClassName : String;
function GetComponentName : String;
function GetConverter : TypeConverter;
function GetDefaultEvent : EventDescriptor;

function GetEvents(attributes : TArrayOfAttribute) :
EventDescriptorCollection; overload;
function GetEvents : EventDescriptorCollection; overload;
function GetDefaultProperty : PropertyDescriptor;

function GetProperties : PropertyDescriptorCollection; overload;
function GetEditor(editorBaseType : System.Type) : TObject;
function GetPropertyOwner(pd : PropertyDescriptor) : TObject;
end;


and my new TPerson class is:
TPerson = class(TMyClass)
fPersonName : String;
fPersonSurName : String;
fPersonAge : Integer;
published
property PersonName : String read fPersonName write fPersonName;
property PersonSurname : String read fPersonSurname write fPersonSurname;
property PersonAge : Integer read fPersonAge write fPersonAge;
end;

**************** IMPLEMENTATIONS BELOW *********************************
{ TMyDescriptor }

function TMyDescriptor.CanResetValue(comp: TObject): Boolean;
begin
Result := base.CanResetValue(comp);
end;


constructor TMyDescriptor.Create(baseP: PropertyDescriptor;
filter: TArrayOfAttribute);
begin
inherited Create(baseP, filter);
Self.base := baseP;
end;

constructor TMyDescriptor.Create(baseP: PropertyDescriptor);
begin
inherited Create(baseP);
Self.base := baseP;
end;

function TMyDescriptor.GetComponentType: &Type;
begin
Result := base.ComponentType;
end;

function TMyDescriptor.GetDisplayName: String;
begin
Result := GetCustomNames(base.Name);
end;

function TMyDescriptor.Getir(baseName : String): String;
begin
if baseName = 'PersonName' then Result := 'Names of the Personel';
if baseName = 'PersonSurname' then Result := 'Surname of the personel';
if baseName = 'PersonAge' then Result := 'Age of the personel';
end;

function TMyDescriptor.GetIsReadOnly: Boolean;
begin
Result := base.IsReadOnly;
end;

function TMyDescriptor.GetName: String;
begin
Result := base.Name;
end;


function TMyDescriptor.GetPropertyType: &Type;
begin
Result := base.PropertyType;
end;

function TMyDescriptor.GetValue(comp: TObject): TObject;
begin
Result := base.GetValue(comp);
end;


procedure TMyDescriptor.ResetValue(comp: TObject);
begin
base.ResetValue(comp);
end;

procedure TMyDescriptor.SetValue(comp, Value: TObject);
begin
base.SetValue(comp, value);
end;

function TMyDescriptor.ShouldSerializeValue(comp: TObject): Boolean;
begin
Result := base.ShouldSerializeValue(comp);
end;

{ TMyClass }

function TMyClass.GetProperties(
filter: TArrayOfAttribute): PropertyDescriptorCollection;
var
baseProps : PropertyDescriptorCollection;
newProps : array of PropertyDescriptor;
iCounter : Integer;
oldname,
newname : String;
begin
baseProps := TypeDescriptor.GetProperties(GetType(), filter);

SetLength(newProps, baseProps.Count);

for iCounter := 0 to baseProps.Count do
begin
newProps[iCounter] := TMyDescriptor.Create(baseProps[iCounter], filter);
// An error occured : E2402 constructing instance of abstract class..
oldname := PropertyDescriptor(baseProps[iCounter]).DisplayName;
newName := TMyDescriptor(newProps[iCounter]).DisplayName;
end;

Result := PropertyDescriptorCollection.Create(newProps);
end;

function TMyClass.GetAttributes: AttributeCollection;
begin
Result := TypeDescriptor.GetAttributes(Self, true);
end;

function TMyClass.GetClassName: String;
begin
Result := TypeDescriptor.GetClassName(Self, true);
end;

function TMyClass.GetComponentName: String;
begin
Result := TypeDescriptor.GetComponentName(Self, true);
end;

function TMyClass.GetConverter: TypeConverter;
begin
Result := TypeDescriptor.GetConverter(Self, true);
end;

function TMyClass.GetDefaultEvent: EventDescriptor;
begin
Result := TypeDescriptor.GetDefaultEvent(Self, true);
end;

function TMyClass.GetDefaultProperty: PropertyDescriptor;
begin
Result := TypeDescriptor.GetDefaultProperty(Self, true);
end;

function TMyClass.GetEditor(editorBaseType: System.Type): TObject;
begin
Result := TypeDescriptor.GetEditor(Self, editorBaseType, true);
end;

function TMyClass.GetEvents: EventDescriptorCollection;
begin
Result := TypeDescriptor.GetEvents(Self, true);
end;

function TMyClass.GetEvents(
attributes: TArrayOfAttribute): EventDescriptorCollection;
begin
Result := TypeDescriptor.GetEvents(Self, attributes, true);
end;

function TMyClass.GetProperties: PropertyDescriptorCollection;
begin
Result := TypeDescriptor.GetProperties(Self, true);
end;

function TMyClass.GetPropertyOwner(pd: PropertyDescriptor): TObject;
begin
Result := Self;
end;


I dont understand what is this. Can anybody helps me , how can i
subclassing PropertyDescriptor class correctly ??


Even we take an error when using delphi.net , we dont take any error
message using c#,

i want change the display name of the property which is the added to my
special class by using the propertyGrid Component ...
It's seems like DisplayNameAttirubute of the .net Framework 2.0

With My Best Regards,

Thanks For Helping


 
Reply With Quote
 
 
 
 
RobinS
Guest
Posts: n/a
 
      4th Dec 2006
I saw this posting in the following groups:

microsoft.public.dotnet.faqs
microsoft.public.dotnet.framework
microsoft.public.dotnet.framework.interop
microsoft.public.dotnet.framework.windowsforms
microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.languages.csharp
microsoft.public.dotnet.general

When you post a message to multiple groups, please post all of
them at once. That way, if someone in one group provides a
solution, the solution will be posted to all of the groups.
Also, if someone in another group is working on a solution,
they will know it has been solved, and they can work on helping
somebody else.

Thanks,
Robin S.
---------------------------------
"Tugrul HELVACI" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I'm using Delphi 2006 and I have a class defination like this:
>
> TPerson = class
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> and i want to display my class instance using PropertyGrid,so...
>
> var
> mPerson : TPerson;
> begin
> mPerson := TPerson.Create;
> mPerson.PersonName := 'Tugrul';
> mPerson.PersonSurname := 'HELVACI';
> mPerson.PersonAge := 31;
> PropertyGrid1.SelectedObject := mPerson;
> end;
>
> at the above code i can see my class instance in the property grid.
> But i want to change property display names in the propertygrid component.
> Because of these, i was searching on the net and i found
> PropertyDescriptor abstract class
> and ICustomTypeConverter interface.
>
> i implemented theese classes following:
>
> TArrayOfAttribute = array of Attribute;
> TMyDescriptor = class(PropertyDescriptor)
> private
> base : PropertyDescriptor;
> fName: String;
>
> function GetName : String;
> function GetDisplayName : String;
> function GetIsReadOnly : Boolean;
> function GetComponentType : &Type;
> function GetPropertyType : &Type;
>
> function GetCustomNames(baseName : String) : String; // my custom names
> getter function
> public
> constructor Create(baseP : PropertyDescriptor; filter :
> TArrayOfAttribute); overload; virtual;
> constructor Create(baseP : PropertyDescriptor); overload; virtual;
>
> function CanResetValue(comp : TObject) : Boolean;
> function GetValue(comp : TObject) : TObject;
>
> procedure ResetValue(comp : TObject);
> procedure SetValue(comp : TObject; Value : TObject);
> function ShouldSerializeValue(comp : TObject) : Boolean;
>
>
> property Name : String read GetName;
> property DisplayName : String read GetDisplayName;
> property IsReadOnly : Boolean read GetIsReadOnly;
> property ComponentType : &Type read GetComponentType;
> property PropertyType : &Type read GetPropertyType;
> end;
>
> TMyClass = class(TInterfacedObject, ICustomTypeDescriptor)
> public
> function GetProperties(filter : TArrayOfAttribute) :
> PropertyDescriptorCollection; overload;
> function GetAttributes : AttributeCollection;
> function GetClassName : String;
> function GetComponentName : String;
> function GetConverter : TypeConverter;
> function GetDefaultEvent : EventDescriptor;
>
> function GetEvents(attributes : TArrayOfAttribute) :
> EventDescriptorCollection; overload;
> function GetEvents : EventDescriptorCollection; overload;
> function GetDefaultProperty : PropertyDescriptor;
>
> function GetProperties : PropertyDescriptorCollection; overload;
> function GetEditor(editorBaseType : System.Type) : TObject;
> function GetPropertyOwner(pd : PropertyDescriptor) : TObject;
> end;
>
>
> and my new TPerson class is:
> TPerson = class(TMyClass)
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write
> fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> **************** IMPLEMENTATIONS BELOW *********************************
> { TMyDescriptor }
>
> function TMyDescriptor.CanResetValue(comp: TObject): Boolean;
> begin
> Result := base.CanResetValue(comp);
> end;
>
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor;
> filter: TArrayOfAttribute);
> begin
> inherited Create(baseP, filter);
> Self.base := baseP;
> end;
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor);
> begin
> inherited Create(baseP);
> Self.base := baseP;
> end;
>
> function TMyDescriptor.GetComponentType: &Type;
> begin
> Result := base.ComponentType;
> end;
>
> function TMyDescriptor.GetDisplayName: String;
> begin
> Result := GetCustomNames(base.Name);
> end;
>
> function TMyDescriptor.Getir(baseName : String): String;
> begin
> if baseName = 'PersonName' then Result := 'Names of the Personel';
> if baseName = 'PersonSurname' then Result := 'Surname of the personel';
> if baseName = 'PersonAge' then Result := 'Age of the personel';
> end;
>
> function TMyDescriptor.GetIsReadOnly: Boolean;
> begin
> Result := base.IsReadOnly;
> end;
>
> function TMyDescriptor.GetName: String;
> begin
> Result := base.Name;
> end;
>
>
> function TMyDescriptor.GetPropertyType: &Type;
> begin
> Result := base.PropertyType;
> end;
>
> function TMyDescriptor.GetValue(comp: TObject): TObject;
> begin
> Result := base.GetValue(comp);
> end;
>
>
> procedure TMyDescriptor.ResetValue(comp: TObject);
> begin
> base.ResetValue(comp);
> end;
>
> procedure TMyDescriptor.SetValue(comp, Value: TObject);
> begin
> base.SetValue(comp, value);
> end;
>
> function TMyDescriptor.ShouldSerializeValue(comp: TObject): Boolean;
> begin
> Result := base.ShouldSerializeValue(comp);
> end;
>
> { TMyClass }
>
> function TMyClass.GetProperties(
> filter: TArrayOfAttribute): PropertyDescriptorCollection;
> var
> baseProps : PropertyDescriptorCollection;
> newProps : array of PropertyDescriptor;
> iCounter : Integer;
> oldname,
> newname : String;
> begin
> baseProps := TypeDescriptor.GetProperties(GetType(), filter);
>
> SetLength(newProps, baseProps.Count);
>
> for iCounter := 0 to baseProps.Count do
> begin
> newProps[iCounter] := TMyDescriptor.Create(baseProps[iCounter],
> filter); // An error occured : E2402 constructing instance of abstract
> class..
> oldname := PropertyDescriptor(baseProps[iCounter]).DisplayName;
> newName := TMyDescriptor(newProps[iCounter]).DisplayName;
> end;
>
> Result := PropertyDescriptorCollection.Create(newProps);
> end;
>
> function TMyClass.GetAttributes: AttributeCollection;
> begin
> Result := TypeDescriptor.GetAttributes(Self, true);
> end;
>
> function TMyClass.GetClassName: String;
> begin
> Result := TypeDescriptor.GetClassName(Self, true);
> end;
>
> function TMyClass.GetComponentName: String;
> begin
> Result := TypeDescriptor.GetComponentName(Self, true);
> end;
>
> function TMyClass.GetConverter: TypeConverter;
> begin
> Result := TypeDescriptor.GetConverter(Self, true);
> end;
>
> function TMyClass.GetDefaultEvent: EventDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultEvent(Self, true);
> end;
>
> function TMyClass.GetDefaultProperty: PropertyDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultProperty(Self, true);
> end;
>
> function TMyClass.GetEditor(editorBaseType: System.Type): TObject;
> begin
> Result := TypeDescriptor.GetEditor(Self, editorBaseType, true);
> end;
>
> function TMyClass.GetEvents: EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, true);
> end;
>
> function TMyClass.GetEvents(
> attributes: TArrayOfAttribute): EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, attributes, true);
> end;
>
> function TMyClass.GetProperties: PropertyDescriptorCollection;
> begin
> Result := TypeDescriptor.GetProperties(Self, true);
> end;
>
> function TMyClass.GetPropertyOwner(pd: PropertyDescriptor): TObject;
> begin
> Result := Self;
> end;
>
>
> I dont understand what is this. Can anybody helps me , how can i
> subclassing PropertyDescriptor class correctly ??
>
>
> Even we take an error when using delphi.net , we dont take any error
> message using c#,
>
> i want change the display name of the property which is the added to my
> special class by using the propertyGrid Component ...
> It's seems like DisplayNameAttirubute of the .net Framework 2.0
>
> With My Best Regards,
>
> Thanks For Helping
>



 
Reply With Quote
 
Gabriel Lozano-Morán
Guest
Posts: n/a
 
      4th Dec 2006
DisplayNameAttribute found in System.ComponentModel

Gabriel Lozano-Morán

"Tugrul HELVACI" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I'm using Delphi 2006 and I have a class defination like this:
>
> TPerson = class
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> and i want to display my class instance using PropertyGrid,so...
>
> var
> mPerson : TPerson;
> begin
> mPerson := TPerson.Create;
> mPerson.PersonName := 'Tugrul';
> mPerson.PersonSurname := 'HELVACI';
> mPerson.PersonAge := 31;
> PropertyGrid1.SelectedObject := mPerson;
> end;
>
> at the above code i can see my class instance in the property grid.
> But i want to change property display names in the propertygrid component.
> Because of these, i was searching on the net and i found
> PropertyDescriptor abstract class
> and ICustomTypeConverter interface.
>
> i implemented theese classes following:
>
> TArrayOfAttribute = array of Attribute;
> TMyDescriptor = class(PropertyDescriptor)
> private
> base : PropertyDescriptor;
> fName: String;
>
> function GetName : String;
> function GetDisplayName : String;
> function GetIsReadOnly : Boolean;
> function GetComponentType : &Type;
> function GetPropertyType : &Type;
>
> function GetCustomNames(baseName : String) : String; // my custom names
> getter function
> public
> constructor Create(baseP : PropertyDescriptor; filter :
> TArrayOfAttribute); overload; virtual;
> constructor Create(baseP : PropertyDescriptor); overload; virtual;
>
> function CanResetValue(comp : TObject) : Boolean;
> function GetValue(comp : TObject) : TObject;
>
> procedure ResetValue(comp : TObject);
> procedure SetValue(comp : TObject; Value : TObject);
> function ShouldSerializeValue(comp : TObject) : Boolean;
>
>
> property Name : String read GetName;
> property DisplayName : String read GetDisplayName;
> property IsReadOnly : Boolean read GetIsReadOnly;
> property ComponentType : &Type read GetComponentType;
> property PropertyType : &Type read GetPropertyType;
> end;
>
> TMyClass = class(TInterfacedObject, ICustomTypeDescriptor)
> public
> function GetProperties(filter : TArrayOfAttribute) :
> PropertyDescriptorCollection; overload;
> function GetAttributes : AttributeCollection;
> function GetClassName : String;
> function GetComponentName : String;
> function GetConverter : TypeConverter;
> function GetDefaultEvent : EventDescriptor;
>
> function GetEvents(attributes : TArrayOfAttribute) :
> EventDescriptorCollection; overload;
> function GetEvents : EventDescriptorCollection; overload;
> function GetDefaultProperty : PropertyDescriptor;
>
> function GetProperties : PropertyDescriptorCollection; overload;
> function GetEditor(editorBaseType : System.Type) : TObject;
> function GetPropertyOwner(pd : PropertyDescriptor) : TObject;
> end;
>
>
> and my new TPerson class is:
> TPerson = class(TMyClass)
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write
> fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> **************** IMPLEMENTATIONS BELOW *********************************
> { TMyDescriptor }
>
> function TMyDescriptor.CanResetValue(comp: TObject): Boolean;
> begin
> Result := base.CanResetValue(comp);
> end;
>
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor;
> filter: TArrayOfAttribute);
> begin
> inherited Create(baseP, filter);
> Self.base := baseP;
> end;
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor);
> begin
> inherited Create(baseP);
> Self.base := baseP;
> end;
>
> function TMyDescriptor.GetComponentType: &Type;
> begin
> Result := base.ComponentType;
> end;
>
> function TMyDescriptor.GetDisplayName: String;
> begin
> Result := GetCustomNames(base.Name);
> end;
>
> function TMyDescriptor.Getir(baseName : String): String;
> begin
> if baseName = 'PersonName' then Result := 'Names of the Personel';
> if baseName = 'PersonSurname' then Result := 'Surname of the personel';
> if baseName = 'PersonAge' then Result := 'Age of the personel';
> end;
>
> function TMyDescriptor.GetIsReadOnly: Boolean;
> begin
> Result := base.IsReadOnly;
> end;
>
> function TMyDescriptor.GetName: String;
> begin
> Result := base.Name;
> end;
>
>
> function TMyDescriptor.GetPropertyType: &Type;
> begin
> Result := base.PropertyType;
> end;
>
> function TMyDescriptor.GetValue(comp: TObject): TObject;
> begin
> Result := base.GetValue(comp);
> end;
>
>
> procedure TMyDescriptor.ResetValue(comp: TObject);
> begin
> base.ResetValue(comp);
> end;
>
> procedure TMyDescriptor.SetValue(comp, Value: TObject);
> begin
> base.SetValue(comp, value);
> end;
>
> function TMyDescriptor.ShouldSerializeValue(comp: TObject): Boolean;
> begin
> Result := base.ShouldSerializeValue(comp);
> end;
>
> { TMyClass }
>
> function TMyClass.GetProperties(
> filter: TArrayOfAttribute): PropertyDescriptorCollection;
> var
> baseProps : PropertyDescriptorCollection;
> newProps : array of PropertyDescriptor;
> iCounter : Integer;
> oldname,
> newname : String;
> begin
> baseProps := TypeDescriptor.GetProperties(GetType(), filter);
>
> SetLength(newProps, baseProps.Count);
>
> for iCounter := 0 to baseProps.Count do
> begin
> newProps[iCounter] := TMyDescriptor.Create(baseProps[iCounter],
> filter); // An error occured : E2402 constructing instance of abstract
> class..
> oldname := PropertyDescriptor(baseProps[iCounter]).DisplayName;
> newName := TMyDescriptor(newProps[iCounter]).DisplayName;
> end;
>
> Result := PropertyDescriptorCollection.Create(newProps);
> end;
>
> function TMyClass.GetAttributes: AttributeCollection;
> begin
> Result := TypeDescriptor.GetAttributes(Self, true);
> end;
>
> function TMyClass.GetClassName: String;
> begin
> Result := TypeDescriptor.GetClassName(Self, true);
> end;
>
> function TMyClass.GetComponentName: String;
> begin
> Result := TypeDescriptor.GetComponentName(Self, true);
> end;
>
> function TMyClass.GetConverter: TypeConverter;
> begin
> Result := TypeDescriptor.GetConverter(Self, true);
> end;
>
> function TMyClass.GetDefaultEvent: EventDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultEvent(Self, true);
> end;
>
> function TMyClass.GetDefaultProperty: PropertyDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultProperty(Self, true);
> end;
>
> function TMyClass.GetEditor(editorBaseType: System.Type): TObject;
> begin
> Result := TypeDescriptor.GetEditor(Self, editorBaseType, true);
> end;
>
> function TMyClass.GetEvents: EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, true);
> end;
>
> function TMyClass.GetEvents(
> attributes: TArrayOfAttribute): EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, attributes, true);
> end;
>
> function TMyClass.GetProperties: PropertyDescriptorCollection;
> begin
> Result := TypeDescriptor.GetProperties(Self, true);
> end;
>
> function TMyClass.GetPropertyOwner(pd: PropertyDescriptor): TObject;
> begin
> Result := Self;
> end;
>
>
> I dont understand what is this. Can anybody helps me , how can i
> subclassing PropertyDescriptor class correctly ??
>
>
> Even we take an error when using delphi.net , we dont take any error
> message using c#,
>
> i want change the display name of the property which is the added to my
> special class by using the propertyGrid Component ...
> It's seems like DisplayNameAttirubute of the .net Framework 2.0
>
> With My Best Regards,
>
> Thanks For Helping
>



 
Reply With Quote
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      4th Dec 2006
Your Property can be decorated with the DisplayNameAttribute directly (at
least from a .NET language. I don't know anything about Delphi)

You may also wish to look at the TypeDescriptionProvider class to use in
conjunction with your custom type descriptor.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Tugrul HELVACI" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I'm using Delphi 2006 and I have a class defination like this:
>
> TPerson = class
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> and i want to display my class instance using PropertyGrid,so...
>
> var
> mPerson : TPerson;
> begin
> mPerson := TPerson.Create;
> mPerson.PersonName := 'Tugrul';
> mPerson.PersonSurname := 'HELVACI';
> mPerson.PersonAge := 31;
> PropertyGrid1.SelectedObject := mPerson;
> end;
>
> at the above code i can see my class instance in the property grid.
> But i want to change property display names in the propertygrid component.
> Because of these, i was searching on the net and i found
> PropertyDescriptor abstract class
> and ICustomTypeConverter interface.
>
> i implemented theese classes following:
>
> TArrayOfAttribute = array of Attribute;
> TMyDescriptor = class(PropertyDescriptor)
> private
> base : PropertyDescriptor;
> fName: String;
>
> function GetName : String;
> function GetDisplayName : String;
> function GetIsReadOnly : Boolean;
> function GetComponentType : &Type;
> function GetPropertyType : &Type;
>
> function GetCustomNames(baseName : String) : String; // my custom names
> getter function
> public
> constructor Create(baseP : PropertyDescriptor; filter :
> TArrayOfAttribute); overload; virtual;
> constructor Create(baseP : PropertyDescriptor); overload; virtual;
>
> function CanResetValue(comp : TObject) : Boolean;
> function GetValue(comp : TObject) : TObject;
>
> procedure ResetValue(comp : TObject);
> procedure SetValue(comp : TObject; Value : TObject);
> function ShouldSerializeValue(comp : TObject) : Boolean;
>
>
> property Name : String read GetName;
> property DisplayName : String read GetDisplayName;
> property IsReadOnly : Boolean read GetIsReadOnly;
> property ComponentType : &Type read GetComponentType;
> property PropertyType : &Type read GetPropertyType;
> end;
>
> TMyClass = class(TInterfacedObject, ICustomTypeDescriptor)
> public
> function GetProperties(filter : TArrayOfAttribute) :
> PropertyDescriptorCollection; overload;
> function GetAttributes : AttributeCollection;
> function GetClassName : String;
> function GetComponentName : String;
> function GetConverter : TypeConverter;
> function GetDefaultEvent : EventDescriptor;
>
> function GetEvents(attributes : TArrayOfAttribute) :
> EventDescriptorCollection; overload;
> function GetEvents : EventDescriptorCollection; overload;
> function GetDefaultProperty : PropertyDescriptor;
>
> function GetProperties : PropertyDescriptorCollection; overload;
> function GetEditor(editorBaseType : System.Type) : TObject;
> function GetPropertyOwner(pd : PropertyDescriptor) : TObject;
> end;
>
>
> and my new TPerson class is:
> TPerson = class(TMyClass)
> fPersonName : String;
> fPersonSurName : String;
> fPersonAge : Integer;
> published
> property PersonName : String read fPersonName write fPersonName;
> property PersonSurname : String read fPersonSurname write
> fPersonSurname;
> property PersonAge : Integer read fPersonAge write fPersonAge;
> end;
>
> **************** IMPLEMENTATIONS BELOW *********************************
> { TMyDescriptor }
>
> function TMyDescriptor.CanResetValue(comp: TObject): Boolean;
> begin
> Result := base.CanResetValue(comp);
> end;
>
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor;
> filter: TArrayOfAttribute);
> begin
> inherited Create(baseP, filter);
> Self.base := baseP;
> end;
>
> constructor TMyDescriptor.Create(baseP: PropertyDescriptor);
> begin
> inherited Create(baseP);
> Self.base := baseP;
> end;
>
> function TMyDescriptor.GetComponentType: &Type;
> begin
> Result := base.ComponentType;
> end;
>
> function TMyDescriptor.GetDisplayName: String;
> begin
> Result := GetCustomNames(base.Name);
> end;
>
> function TMyDescriptor.Getir(baseName : String): String;
> begin
> if baseName = 'PersonName' then Result := 'Names of the Personel';
> if baseName = 'PersonSurname' then Result := 'Surname of the personel';
> if baseName = 'PersonAge' then Result := 'Age of the personel';
> end;
>
> function TMyDescriptor.GetIsReadOnly: Boolean;
> begin
> Result := base.IsReadOnly;
> end;
>
> function TMyDescriptor.GetName: String;
> begin
> Result := base.Name;
> end;
>
>
> function TMyDescriptor.GetPropertyType: &Type;
> begin
> Result := base.PropertyType;
> end;
>
> function TMyDescriptor.GetValue(comp: TObject): TObject;
> begin
> Result := base.GetValue(comp);
> end;
>
>
> procedure TMyDescriptor.ResetValue(comp: TObject);
> begin
> base.ResetValue(comp);
> end;
>
> procedure TMyDescriptor.SetValue(comp, Value: TObject);
> begin
> base.SetValue(comp, value);
> end;
>
> function TMyDescriptor.ShouldSerializeValue(comp: TObject): Boolean;
> begin
> Result := base.ShouldSerializeValue(comp);
> end;
>
> { TMyClass }
>
> function TMyClass.GetProperties(
> filter: TArrayOfAttribute): PropertyDescriptorCollection;
> var
> baseProps : PropertyDescriptorCollection;
> newProps : array of PropertyDescriptor;
> iCounter : Integer;
> oldname,
> newname : String;
> begin
> baseProps := TypeDescriptor.GetProperties(GetType(), filter);
>
> SetLength(newProps, baseProps.Count);
>
> for iCounter := 0 to baseProps.Count do
> begin
> newProps[iCounter] := TMyDescriptor.Create(baseProps[iCounter],
> filter); // An error occured : E2402 constructing instance of abstract
> class..
> oldname := PropertyDescriptor(baseProps[iCounter]).DisplayName;
> newName := TMyDescriptor(newProps[iCounter]).DisplayName;
> end;
>
> Result := PropertyDescriptorCollection.Create(newProps);
> end;
>
> function TMyClass.GetAttributes: AttributeCollection;
> begin
> Result := TypeDescriptor.GetAttributes(Self, true);
> end;
>
> function TMyClass.GetClassName: String;
> begin
> Result := TypeDescriptor.GetClassName(Self, true);
> end;
>
> function TMyClass.GetComponentName: String;
> begin
> Result := TypeDescriptor.GetComponentName(Self, true);
> end;
>
> function TMyClass.GetConverter: TypeConverter;
> begin
> Result := TypeDescriptor.GetConverter(Self, true);
> end;
>
> function TMyClass.GetDefaultEvent: EventDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultEvent(Self, true);
> end;
>
> function TMyClass.GetDefaultProperty: PropertyDescriptor;
> begin
> Result := TypeDescriptor.GetDefaultProperty(Self, true);
> end;
>
> function TMyClass.GetEditor(editorBaseType: System.Type): TObject;
> begin
> Result := TypeDescriptor.GetEditor(Self, editorBaseType, true);
> end;
>
> function TMyClass.GetEvents: EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, true);
> end;
>
> function TMyClass.GetEvents(
> attributes: TArrayOfAttribute): EventDescriptorCollection;
> begin
> Result := TypeDescriptor.GetEvents(Self, attributes, true);
> end;
>
> function TMyClass.GetProperties: PropertyDescriptorCollection;
> begin
> Result := TypeDescriptor.GetProperties(Self, true);
> end;
>
> function TMyClass.GetPropertyOwner(pd: PropertyDescriptor): TObject;
> begin
> Result := Self;
> end;
>
>
> I dont understand what is this. Can anybody helps me , how can i
> subclassing PropertyDescriptor class correctly ??
>
>
> Even we take an error when using delphi.net , we dont take any error
> message using c#,
>
> i want change the display name of the property which is the added to my
> special class by using the propertyGrid Component ...
> It's seems like DisplayNameAttirubute of the .net Framework 2.0
>
> With My Best Regards,
>
> Thanks For Helping
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing DisplayNames of my properties using PropertyGrid component, how ?? Tugrul HELVACI Microsoft Dot NET Framework 3 5th Dec 2006 11:41 AM
Changing DisplayNames of my properties using PropertyGrid component, how ?? Tugrul HELVACI Microsoft C# .NET 4 4th Dec 2006 07:03 PM
Changing DisplayNames of my properties using PropertyGrid component, how ?? Tugrul HELVACI Microsoft Dot NET 2 4th Dec 2006 07:02 PM
readonly properties when displaying an object's properties in propertygrid movieknight@gmail.com Microsoft VB .NET 0 14th May 2006 06:48 AM
PropertyGrid with duplicate DisplayNames mail@jasper-moeller.de Microsoft Dot NET Framework Forms 0 7th Apr 2006 05:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:51 AM.