PDA

View Full Version : Subitems in VCL properties?


Obeliks
03-18-2002, 08:04 AM
Hi folks...

Here comes a further question:

When writing a component, how can I put some properties as subitems under another property...
(sorry, no one will be able to understand this sentence... Therefore here comes an outline of my thinking:)

<tt>
<cb> SomeProperty</cb>
<cr>- DetailView | (TDetailView)</cr>
<ct> Column | 0
Visible | True</ct>
<cb> AnotherProperty
+ AnotherPropertyWithSubitemsButClosed
TheLastProperty</cb>


etc...
</tt>

I hope now everyone knows what I mean and at least one of you can help me (it's a simple thing, just can't figure it out)...

THX,
Obeliks

<tt>*_______________
| |
| <ct>member of the</ct> |
| <cb>c</cb><cr>razy</cr> |
| <cb>c</cb><cr>oders</cr> |
| <cb>c</cb><cr>lub</cr> |
|_______________|
</tt>

Ted On The NeT
03-18-2002, 08:08 AM
type
TDetailView = class( TPersistent)
private
FColumn : integer;
FVisible : boolean;
public
constructor Create( AOwner: TComponent);
published
property Column : integer read GetColumn write SetColumn default 0;
property EnterIsTab : boolean read FVisible write FVisible default false;
end;

<tt>
Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
don't forget to accept this reply if it helped you! :)
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
</tt>

Ted On The NeT
03-18-2002, 08:15 AM
In your component, add this:
TMyComponent
{...}
private
FDetailView: TDetailView;
{..}
published
property DetailView : TDetailView read FTDetailView write TDetailView;

{..}

code:
Constructor TDetailView.Create( Aowner : TComponent);
begin
// default values!
Column := 0;
Visible := False;
end;

{..}

constructor TMyComponent.Create(AOwner: TComponent);
begin
{...}
FDetailView := TDetailView.Create(Self);
end;

That should do it!

<tt>
Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
don't forget to accept this reply if it helped you! :)
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
</tt>

Obeliks
03-18-2002, 08:18 AM
Thanks, but (again) I got this far on my own already... My problem is that although the property appears in the Object Viewer (even with the +) the subitems are not displayed, just a - in front of the property, but no subitems...

Where's the mistake?

So long,
Obeliks

<tt>*_______________
| |
| <ct>member of the</ct> |
| <cb>c</cb><cr>razy</cr> |
| <cb>c</cb><cr>oders</cr> |
| <cb>c</cb><cr>lub</cr> |
|_______________|
</tt>

GoodFun
03-18-2002, 09:15 AM
can you post your class definition in there? I would need to see the class that you want to have included as a expandable list as well as the one that should hold that class as a property...

Hope this helps,

Marcel

<cr>Please click on Accept if this helped...</cr>

Obeliks
03-18-2002, 09:34 AM
Ok, here is the whole unit (was easier to copy *g*) I just shortened the published properties of TCustomListBox.


<tt><cr>unit</cr> OutlookListBox;

<cr>interface</cr>

<cr>uses</cr>
Windows, Dialogs, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics;

<cr>type</cr>
TDetailView = <cr>class</cr>(TPersistent)
<cr>private</cr>
FColumn: Integer;
FFont: TFont;
FHeight: Integer;
FIdent: Integer;
FVisible: Boolean;
<cr>public</cr>
<cr>constructor</cr> Create(AOwner: TComponent);
<cr>published</cr>
<cr>property</cr> Column: Integer <cr>read</cr> FColumn <cr>write</cr> FColumn;
<cr>property</cr> Font: TFont <cr>read</cr> FFont <cr>write</cr> FFont;
<cr>property</cr> Height: Integer <cr>read</cr> FHeight <cr>write</cr> FHeight;
<cr>property</cr> Ident: Integer <cr>read</cr> FIdent <cr>write</cr> FIdent;
<cr>property</cr> Visible: Boolean <cr>read</cr> FVisible <cr>write</cr> FVisible;
<cr>end;</cr>
TOutlookListBox = <cr>class</cr>(TCustomListBox)
FDetailView: TDetailView;
<cr>private</cr>
<cb>{ Private-Deklarationen }</cb>
<cr>procedure</cr> PaintText(Canvas:TCanvas;Text:String;Left,Top,Widt h,Height:Integer);
<cr>procedure</cr> SetDetailView(const Value: TDetailView);
<cr>protected</cr>
<cr>property</cr> ItemHeight;
<cb>{ Protected-Deklarationen }</cb>
<cr>public</cr>
<cr>constructor</cr> Create(AOwner: TComponent);
<cb>{ Public-Deklarationen }</cb>
<cr>published</cr>
<cr>property</cr> DetailView: TDetailView <cr>read</cr> FDetailView <cr>write</cr> SetDetailView;

property Style;
[...]
property OnStartDrag;
<cb>{ Published-Deklarationen }</cb>
<cr>end;</cr>

<cr>procedure</cr> Register;

implementation

<cr>procedure</cr> Register;
<cr>begin</cr>
RegisterComponents('Obeliks', [TOutlookListBox]);
<cr>end;</cr>

<cb>{ TOutlookListBox }</cb>

<cr>constructor</cr> TOutlookListBox.Create(AOwner: TComponent);
<cr>begin</cr>
inherited Create(AOwner);
FDetailView:=TDetailView.Create(Self);
<cr>end;</cr>

<cr>procedure</cr> TOutlookListBox.PaintText(Canvas: TCanvas; Text: String; Left,
Top, Width, Height: Integer);
var ARect:TRect;
<cr>begin</cr>
ARect:=Bounds(Left,Top,Width,Height);
DrawText(Canvas.handle,PChar(Text),length(Text),AR ect,dt_noprefix or dt_wordbreak or dt_left or DT_END_ELLIPSIS or DT_MODIFYSTRING);
<cr>end;</cr>

<cr>procedure</cr> TOutlookListBox.SetDetailView(const Value: TDetailView);
<cr>begin</cr>
FDetailView := Value;
Showmessage(<cr>'Test'</cr>);
<cr>end;</cr>



<cb>{ TDetailView }</cb>

<cr>constructor</cr> TDetailView.Create(AOwner: TComponent);
<cr>begin</cr>
inherited Create;
FColumn:=1;
FFont.Color:=clBlue;
FFont.Name:='Tahoma';
FFont.Size:=8;
FHeight:=48;
FIdent:=20;
FVisible:=True;
<cr>end;</cr>

<cr>end.</cr></tt>

<tt>*_______________
| |
| <ct>member of the</ct> |
| <cb>c</cb><cr>razy</cr> |
| <cb>c</cb><cr>oders</cr> |
| <cb>c</cb><cr>lub</cr> |
|_______________|
</tt>

GoodFun
03-18-2002, 09:57 AM
The only thing I can see that I do different in my component is that I made an Assign function and used that in the Set procedure...
<cb>
procedure TThumbnailInfo.Assign(Source: TPersistent);
begin
if (Source is TThumbnailInfo) then
begin
with (TThumbnailInfo(Source)) do
begin
Self.Width := Width;
Self.Height := Height;
Self.FMultiSelect := FMultiSelect;
Self.Parent := Parent;
end;
end
else
begin
inherited; // raises an exception
end;
end;

procedure TCustomTiffManager.SetThumbnailInfo(const Data: TThumbnailInfo);
begin
FThumbnailInfo.Assign(Data);
end;
</cb>

Hope this helps,

Marcel

<cr>Please click on Accept if this helped...</cr>

Ted On The NeT
03-19-2002, 12:34 AM
okay, some notes to the piece of code below: kick out the SetDetailFunction out of the code, and do Write FDetailView.
The procedure is not needed!
<cb>
published
property DetailView: TDetailView read FDetailView write SetDetailView;
</cb>

normally, if no properties exist when clicking on the [+], the properties are not in the published part, but in the private part.

<tt>
Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
don't forget to accept this reply if it helped you! :)
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
</tt>

Obeliks
03-19-2002, 05:59 AM
But if you look at the code, then you'll see that the properties are defined in the <cr>published</cr> section...

And the SetDetailView procedure... Ok, you're right, but there's coming some code when I've fixed this problem, so I will need it...

So long,
Obeliks

<tt>*_______________
| |
| <ct>member of the</ct> |
| <cb>c</cb><cr>razy</cr> |
| <cb>c</cb><cr>oders</cr> |
| <cb>c</cb><cr>lub</cr> |
|_______________|
</tt>

Ted On The NeT
03-19-2002, 06:07 AM
well, i wasn't suggesting you are stupid or something. I just said this is what usually is the problem when the properties don't exist.

can't you send me the complete unit, so i'd be able to compile it my self and see if I can debug it?
(xoompager@hotmail.com)

<tt>
Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
don't forget to accept this reply if it helped you! :)
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
</tt>

Ted On The NeT
03-19-2002, 05:34 PM
Hi Obeliks,

i found your problem!

<cb>constructor TDetailView.Create(AOwner: TComponent);
begin
// inherited Create; <ct>DELETE THIS PART! not the problem, but you did not override the base create (because it does not exist!</ct>
FColumn:=1;
<cr>THIS IS THE PROBLEM:
===> FFont := TFont.Create;
YOU MISS THIS PART! :-)</cr>
FFont.Color:=clBlue;
FFont.Name:='Tahoma';
FFont.Size:=8;
FHeight:=48;
FIdent:=20;
FVisible:=True;
end;
</cb>

I'll email you the modified code, because there where some other things wrong as well, which may have given you troubles in the future!

<tt>
Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
<ct>don't forget to accept this reply if it helped you! :)</ct>
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
</tt>