 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sarfraz Bokhari Guest
|
Posted: Fri Aug 15, 2003 6:33 pm Post subject: How to create to share among several components -- Nested pr |
|
|
Hi group,
Using WinXP, Delphi 7
I have some properties those should be shaed among number of components let
Prop1, Prop2, etc. I want to create a groups of properties and their
implementation and then re-use among serval classes. Please read following
code sample.
Something like this.
type
TMyProperties = class;
private
FProp1 : boolean;
FProp2 : string;
... some other properties of classes types ......
protected
procedure SetProp2(AVal : string);
public
published
Prop1 : boolean read FProp1 write FProp1;
Prop2 : sting read FProp2 write SetProp2;
end;
type
MyControl1 = class(SomeControl1)
private
FMyProp : TMyProperties
FProp3 : integer;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
type
MyControl2 = class(SomeControl2)
private
FMyProp : TMyProperties
FProp3 : SomeType;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
implementation
.......
create MyProperties in constructor and Free in destructor .........
......
1. Now what steps should be taken to expose MyProperties in
ObjectInspector because if I click in ObjectInspector, Delphi reports
"unable to expand"
2. Should I create a member, say Ower, so TMyProperties knows to whom it
belongs to or how to get/set the properties of the class in which
TMyProperties exists?
3. I should consider new way. Pease give some examples
Thanks in advance
S. Bokhari
|
|
| Back to top |
|
 |
Alain Quesnel Guest
|
Posted: Sat Aug 16, 2003 4:53 am Post subject: Re: How to create to share among several components -- Neste |
|
|
In addition to making TMyProperties a descendant of TPersistent, you need to
initialize your private field FMyProp in the constructor and free it in the
destructor. And look at the Set methods for MyProp. Like so (untested):
unit Unit2;
interface
uses Classes, Controls, SysUtils;
type
TMyProperties = class(TPersistent)
private
FProp1: boolean;
FProp2: string;
procedure SetProp2(const Value: string);
published
property Prop1 : boolean read FProp1 write FProp1;
property Prop2 : string read FProp2 write SetProp2;
end;
MyControl1 = class(TControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
MyControl2 = class(TCustomControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
implementation
{ TMyProperties }
procedure TMyProperties.SetProp2(const Value: string);
begin
FProp2 := Value;
end;
{ MyControl1 }
constructor MyControl1.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl1.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl1.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
{ MyControl2 }
constructor MyControl2.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl2.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl2.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
end.
--
Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]
www.logiquel.com
"D Whaley" <dwhaley (AT) hs-technologies (DOT) com> wrote
| Quote: | TMyProperties = class(tPersistent);
"Sarfraz Bokhari" <sarfraz_bokhari (AT) yahoo (DOT) com> wrote in message
news:3f3d31dc (AT) newsgroups (DOT) borland.com...
Hi group,
Using WinXP, Delphi 7
I have some properties those should be shaed among number of components
let
Prop1, Prop2, etc. I want to create a groups of properties and their
implementation and then re-use among serval classes. Please read
following
code sample.
Something like this.
type
TMyProperties = class;
private
FProp1 : boolean;
FProp2 : string;
... some other properties of classes types ......
protected
procedure SetProp2(AVal : string);
public
published
Prop1 : boolean read FProp1 write FProp1;
Prop2 : sting read FProp2 write SetProp2;
end;
type
MyControl1 = class(SomeControl1)
private
FMyProp : TMyProperties
FProp3 : integer;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
type
MyControl2 = class(SomeControl2)
private
FMyProp : TMyProperties
FProp3 : SomeType;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
implementation
......
create MyProperties in constructor and Free in destructor .........
.....
1. Now what steps should be taken to expose MyProperties in
ObjectInspector because if I click in ObjectInspector, Delphi reports
"unable to expand"
2. Should I create a member, say Ower, so TMyProperties knows to whom
it
belongs to or how to get/set the properties of the class in which
TMyProperties exists?
3. I should consider new way. Pease give some examples
Thanks in advance
S. Bokhari
|
|
|
| Back to top |
|
 |
Sarfraz Bokhari Guest
|
Posted: Sun Aug 17, 2003 1:20 pm Post subject: Re: How to create to share among several components -- Neste |
|
|
Thanks,
I will try it next week because I have been assigned another small propject.
I have still one question, in TMyProperties class methods I want to
manipulate parent class properties. How could it possible. Should I write
code something like
procedure Create(AOwer.........)
begin
FMyProp := TMYProperties.Create;
FMyProp.SetParent(Self);
--- but how to manipulate Private Members of "Self" in TMyProperties
methods.
--- or I should consider some other path.
end;
Thanks your reply.
S. Bokhari
"Alain Quesnel" <alainsansspam (AT) logiquel (DOT) com> wrote
| Quote: | In addition to making TMyProperties a descendant of TPersistent, you need
to
initialize your private field FMyProp in the constructor and free it in
the
destructor. And look at the Set methods for MyProp. Like so (untested):
unit Unit2;
interface
uses Classes, Controls, SysUtils;
type
TMyProperties = class(TPersistent)
private
FProp1: boolean;
FProp2: string;
procedure SetProp2(const Value: string);
published
property Prop1 : boolean read FProp1 write FProp1;
property Prop2 : string read FProp2 write SetProp2;
end;
MyControl1 = class(TControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
MyControl2 = class(TCustomControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
implementation
{ TMyProperties }
procedure TMyProperties.SetProp2(const Value: string);
begin
FProp2 := Value;
end;
{ MyControl1 }
constructor MyControl1.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl1.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl1.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
{ MyControl2 }
constructor MyControl2.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl2.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl2.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
end.
--
Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]
www.logiquel.com
"D Whaley" <dwhaley (AT) hs-technologies (DOT) com> wrote in message
news:3f3d3470 (AT) newsgroups (DOT) borland.com...
TMyProperties = class(tPersistent);
"Sarfraz Bokhari" <sarfraz_bokhari (AT) yahoo (DOT) com> wrote in message
news:3f3d31dc (AT) newsgroups (DOT) borland.com...
Hi group,
Using WinXP, Delphi 7
I have some properties those should be shaed among number of
components
let
Prop1, Prop2, etc. I want to create a groups of properties and their
implementation and then re-use among serval classes. Please read
following
code sample.
Something like this.
type
TMyProperties = class;
private
FProp1 : boolean;
FProp2 : string;
... some other properties of classes types ......
protected
procedure SetProp2(AVal : string);
public
published
Prop1 : boolean read FProp1 write FProp1;
Prop2 : sting read FProp2 write SetProp2;
end;
type
MyControl1 = class(SomeControl1)
private
FMyProp : TMyProperties
FProp3 : integer;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
type
MyControl2 = class(SomeControl2)
private
FMyProp : TMyProperties
FProp3 : SomeType;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
implementation
......
create MyProperties in constructor and Free in destructor .........
.....
1. Now what steps should be taken to expose MyProperties in
ObjectInspector because if I click in ObjectInspector, Delphi reports
"unable to expand"
2. Should I create a member, say Ower, so TMyProperties knows to
whom
it
belongs to or how to get/set the properties of the class in which
TMyProperties exists?
3. I should consider new way. Pease give some examples
Thanks in advance
S. Bokhari
|
|
|
| Back to top |
|
 |
Alain Quesnel Guest
|
Posted: Sun Aug 17, 2003 10:06 pm Post subject: Re: How to create to share among several components -- Neste |
|
|
If you want to use the owner of TMyProperties, then that class would have to
inherit from TComponent instead of TPersistent. However, I'm not sure it's
"proper" to do so. And don't confuse Parent and Owner, they are two quite
different concepts.
--
Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]
www.logiquel.com
"Sarfraz Bokhari" <sarfraz_bokhari (AT) yahoo (DOT) com> wrote
| Quote: | Thanks,
I will try it next week because I have been assigned another small
propject.
I have still one question, in TMyProperties class methods I want to
manipulate parent class properties. How could it possible. Should I write
code something like
procedure Create(AOwer.........)
begin
FMyProp := TMYProperties.Create;
FMyProp.SetParent(Self);
--- but how to manipulate Private Members of "Self" in TMyProperties
methods.
--- or I should consider some other path.
end;
Thanks your reply.
S. Bokhari
"Alain Quesnel" <alainsansspam (AT) logiquel (DOT) com> wrote in message
news:3f3db8d4$1 (AT) newsgroups (DOT) borland.com...
In addition to making TMyProperties a descendant of TPersistent, you
need
to
initialize your private field FMyProp in the constructor and free it in
the
destructor. And look at the Set methods for MyProp. Like so (untested):
unit Unit2;
interface
uses Classes, Controls, SysUtils;
type
TMyProperties = class(TPersistent)
private
FProp1: boolean;
FProp2: string;
procedure SetProp2(const Value: string);
published
property Prop1 : boolean read FProp1 write FProp1;
property Prop2 : string read FProp2 write SetProp2;
end;
MyControl1 = class(TControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
MyControl2 = class(TCustomControl)
private
FMyProp : TMyProperties;
procedure SetMyProp(const Value: TMyProperties);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property MyProperties : TMyProperties read FMyProp write SetMyProp;
end;
implementation
{ TMyProperties }
procedure TMyProperties.SetProp2(const Value: string);
begin
FProp2 := Value;
end;
{ MyControl1 }
constructor MyControl1.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl1.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl1.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
{ MyControl2 }
constructor MyControl2.Create(AOwner: TComponent);
begin
inherited;
FMyProp := TMyProperties.Create;
end;
destructor MyControl2.Destroy;
begin
FreeAndNil(FMyProp);
inherited;
end;
procedure MyControl2.SetMyProp(const Value: TMyProperties);
begin
FMyProp.Assign(Value);
end;
end.
--
Alain Quesnel
[email]alainsansspam (AT) logiquel (DOT) com[/email]
www.logiquel.com
"D Whaley" <dwhaley (AT) hs-technologies (DOT) com> wrote in message
news:3f3d3470 (AT) newsgroups (DOT) borland.com...
TMyProperties = class(tPersistent);
"Sarfraz Bokhari" <sarfraz_bokhari (AT) yahoo (DOT) com> wrote in message
news:3f3d31dc (AT) newsgroups (DOT) borland.com...
Hi group,
Using WinXP, Delphi 7
I have some properties those should be shaed among number of
components
let
Prop1, Prop2, etc. I want to create a groups of properties and their
implementation and then re-use among serval classes. Please read
following
code sample.
Something like this.
type
TMyProperties = class;
private
FProp1 : boolean;
FProp2 : string;
... some other properties of classes types ......
protected
procedure SetProp2(AVal : string);
public
published
Prop1 : boolean read FProp1 write FProp1;
Prop2 : sting read FProp2 write SetProp2;
end;
type
MyControl1 = class(SomeControl1)
private
FMyProp : TMyProperties
FProp3 : integer;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
type
MyControl2 = class(SomeControl2)
private
FMyProp : TMyProperties
FProp3 : SomeType;
proteced
{what should I do in this procedure or it is not requires.}
procedure SetMyProp( AMyProp : TMyProperties);
published
property MyProperties : TMyProperties read FMyProp write
SetMyProp;
end;
implementation
......
create MyProperties in constructor and Free in destructor .........
.....
1. Now what steps should be taken to expose MyProperties in
ObjectInspector because if I click in ObjectInspector, Delphi
reports
"unable to expand"
2. Should I create a member, say Ower, so TMyProperties knows to
whom
it
belongs to or how to get/set the properties of the class in which
TMyProperties exists?
3. I should consider new way. Pease give some examples
Thanks in advance
S. Bokhari
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|