Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: code interpretation in OOP


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 11, 2018 10:38 PM Last Post By: Lex Dean
Lex Dean

Posts: 132
Registered: 3/26/07
code interpretation in OOP  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2018 11:39 AM
I have written Tbar that contains a a TCollection descendant

TabTBar = class(TPannel)

published
property Buttons: TButts read FButs write SetButs;

................
................

procedure TabTBar.SetButs(const Value: TButts);
begin
FButs.Assign(Value);
end;
end.

in my code using the object I write

Tbar.Buttons[11].ComBoBox.Items.Add(intToStr(I));

The reference "Tbar.Buttons[11]" the compiler does not like?

When I build this line I have to write manually in the IDE 'Items.Add(intToStr(I));'

but when I make a reference as below everything is fine
var aComboDevType: TButt
begin
aComboDevType := Tbar.Buttons[11];
...............
...............
aComboDevType.ComBoBox.Items.Add('Info');

The IDE and compiler works fine

what can I do to simply write "Tbar.Buttons[11].ComBoBox.Items.Add(intToStr(I));"

The compiler does not accept the full line and does not give the short cut options from the IDE menu
And it crashes because it does not understand its own Delphi code.
Yes it is a lot of objects to jump through but is their a better reason?
TBar also holds TEdit too with the same problems

Delphi 7

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: code interpretation in OOP [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2018 1:34 AM   in response to: Lex Dean in response to: Lex Dean
Lex Dean wrote:

I havre written Tbar that contains a a TCollection descendant

TabTBar = class(TPannel)

published
property Buttons: TButts read FButs write SetButs;

................
................

procedure TabTBar.SetButs(const Value: TButts);
begin
FButs.Assign(Value);
end;
end.

in my code using the object I write

Tbar.Buttons[11].ComBoBox.Items.Add(intToStr(I));

The reference "Tbar.Buttons[11]" the compiler does not like?

How is the Items property of TButts defined? If you inherit TButts from
TCOllection and not redefine the property Items will return a
TCollectionItem, which does not have a ComBoBox property. You can only
get around that be using an explicit typecast, like

TButt(Tbar.Buttons[11]).Combobox

The alternative would be to define an additional, public, array
property on the TabTBar class that returns TButt instead of
TCollectionitem, basically hiding the typecast inside the code for the
Get method of this property.

--
Peter Below
TeamB
Lex Dean

Posts: 132
Registered: 3/26/07
Re: code interpretation in OOP [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2018 10:38 PM   in response to: Peter Below in response to: Peter Below
Good question peter, Did not give you that

How is the Items property of TButts defined? If you inherit TButts from
TCOllection and not redefine the property Items will return a
TCollectionItem, which does not have a ComBoBox property. You can only
get around that be using an explicit typecast, like

TButt(Tbar.Buttons[11]).Combobox

The alternative would be to define an additional, public, array
property on the TabTBar class that returns TButt instead of
TCollectionitem, basically hiding the typecast inside the code for the
Get method of this property.

--
Peter Below
TeamB

TCollection desendant uses a standard TCollectionItem descendant that contains
TButtstyle = (ttButton, ttToggle, ttDivider, ttDropDown, ttGroup, ttSpacer, ttComboBox, ttEditor);

It then produces one object according to this setting and attaches pointer reference in TCollectionItem descendant
ttButton, ttToggle, ttDivider, ttDropDown, ttGroup, ttSpacer, is made from one GraphicControl descendant object.
And the parent is TabBar so they are displaying in the TBar and TBar send messages to the object (except mouse).

a) GraphicControl descendant displays Hints but not TEdit and TComboBox created in the same method even.
My code heavily depends on "If FComboBox <> Nil then FComboBox......" to avoid crashes.
b) The IDE and the compiler do not like reading through the TCollection descendant to TCollectionItem descendant very well. All ways giving the TCollectionItem descendant but not after the TCollectionItem descendant. When I make a pointer to the TCollectionItem descendant, objects after the descendant work properly in every respect (Stable).
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02