 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
masi Guest
|
Posted: Fri Mar 10, 2006 3:03 pm Post subject: DYNAMIC - overload? |
|
|
1) what does exactly mean the word DYNAMIC that i must type when for example
i want to modify the standard handler of an event like MouseDown:
DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift,
int X, int Y);
//---------------------------------------------------------------------------
void __fastcall MyControl::MouseDown(TMouseButton Button,
Classes::TShiftState Shift, int X, int Y)
{
// do something before
TCustomControl::MouseDown(Button,Shift,X,Y); // perform standard
handling, including calling handler
// do something after
}
2) what does exactly mean the keyword overload in the pascal declaration of
a method? what is the correspondance in c++?
thanks
masi urbano |
|
| Back to top |
|
 |
masi Guest
|
Posted: Fri Mar 10, 2006 11:03 pm Post subject: Re: DYNAMIC - overload? |
|
|
What I'm trying to do is to modify the TVirtualStringTree class in order to
implement a new event that behaves like TListView::OnSelectItem event.
I'm working so:
typedef void __fastcall (__closure *NodeChangeSelectEvent)(TObject *Sender,
TVirtualNode *Node, bool Selected);
class PACKAGE MyVirtualTree : public TVirtualStringTree
{
private:
NodeChangeSelectEvent POnNodeChangeSelect;
// event trigger
void __fastcall NodeChangeSelect(TVirtualNode *Node, bool Selected);
protected:
void __fastcall AddToSelection(TVirtualNode *Node);
void __fastcall RemoveFromSelection(TVirtualNode *Node);
public:
__fastcall MyVirtualTree(TComponent* Owner);
__published:
__property NodeChangeSelectEvent OnNodeChangeSelect =
{read=POnNodeChangeSelect, write=POnNodeChangeSelect};
};
//---------------------------------------------------------------------------
__fastcall MyVirtualTree::MyVirtualTree(TComponent* Owner) :
TVirtualStringTree(Owner)
{
///
}
//---------------------------------------------------------------------------
void __fastcall MyVirtualTree::AddToSelection(TVirtualNode *Node)
{
TVirtualStringTree::AddToSelection(Node);
// fire event
NodeChangeSelect(Node,true);
}
//---------------------------------------------------------------------------
void __fastcall MyVirtualTree::RemoveFromSelection(TVirtualNode *Node)
{
TVirtualStringTree::RemoveFromSelection(Node);
// fire event
NodeChangeSelect(Node,false);
}
//---------------------------------------------------------------------------
void __fastcall MyVirtualTree::NodeChangeSelect(TVirtualNode *Node, bool
Selected) // event trigger
{
if (!Enabled) return;
if (POnNodeChangeSelect != NULL){
POnNodeChangeSelect(this,Node,Selected);
}
}
//---------------------------------------------------------------------------
Then I would expect that when I select or deselect an item,
MyVirtualTree::AddToSelection or MyVirtualTree::RemoveFromSelection would be
called, but it doesn't happen at all!
in VirtualTrees.hpp (machine generated header for VirtualTrees.pas) I found:
protected:
void __fastcall AddToSelection(PVirtualNode Node)/* overload */;
where /* overload */ is just an auto-generated comment
so, as far as I know, what I have to do is to declare in my class
MyVirtualTree
void __fastcall AddToSelection(PVirtualNode Node);
I tried so and even
void __fastcall AddToSelection(TVirtualNode *Node);
which is the same, but none works.
Any ideas?
thanks
masi urbano |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Mar 10, 2006 11:03 pm Post subject: Re: DYNAMIC - overload? |
|
|
"masi" <masiurb (AT) tin (DOT) it> wrote in message
news:44118344$1 (AT) newsgroups (DOT) borland.com...
| Quote: | what does exactly mean the word DYNAMIC that i must type when for
example i want to modify the standard handler of an event like MouseDown:
|
DYNAMIC is a precompiler macro that expends to __declspec(dynamic). Any VCL
method that is declared with the 'dynamic' keyword in Delphi has to be
declared with __declspec(dynamic) in C++ in order to operate proprly. A
dynamic method is essentially the same as a virtual method, but it has
slightly different semantics internally, which you are read about in the
documentation for __declspec().
| Quote: | what does exactly mean the keyword overload in the pascal declaration
of a method?
|
Exactly what its name suggests - it specifies that the method is overriding
a virtual or dynamic method in a base class. In Delphi, the 'override'
keyword is required in order to actually override the method. In C++, there
is no such keyword. Overriding is always implicitally handled.
Gambit |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Mar 11, 2006 1:03 am Post subject: Re: DYNAMIC - overload? |
|
|
"masi" <masiurb (AT) tin (DOT) it> wrote in message
news:4411f2fa (AT) newsgroups (DOT) borland.com...
| Quote: | I would expect that when I select or deselect an item,
MyVirtualTree::AddToSelection or MyVirtualTree::RemoveFromSelection
would be called, but it doesn't happen at all!
|
Those methods are not virtual or dynamic to begin with, so you cannot
override them. You will have to either find another way to accomplish what
you want, or else you will have to edit the original Delphi source code for
TVirtualStringTree to make the methods virtual and then recompile that
component.
| Quote: | void __fastcall AddToSelection(PVirtualNode Node)/* overload */;
where /* overload */ is just an auto-generated comment
|
Sorry, I thought you said 'override' earlier. The 'overload' keyword is
completely different and unrelated. It means exactly what its name
suggests - the method is overloaded, which means the same thing in Delphi
that it does in C++. A method is overloaded when there are more than 1
method of the same name in the same class, just with different parameter
lists.
Gambit |
|
| Back to top |
|
 |
Rudy Velthuis [TeamB] Guest
|
Posted: Sun Mar 12, 2006 2:03 am Post subject: Re: DYNAMIC - overload? |
|
|
At 14:46:26, 10.03.2006, masi wrote:
| Quote: |
1) what does exactly mean the word DYNAMIC that i must type when for
example i want to modify the standard handler of an event like
MouseDown:
|
Dynamic is a special kind of virtual, first defined for the Turbo Pascal
compiler, when dat segments were limited, and virtual tables of, for
instance, the Turbo Vision framework could easily gobble up all the 64k
available. So Borland defined some kind of slower, but less memory
consuming virtual method table, the dynamic method table.
It does not contain a long list (indexed array) of ALL the function
pointers, which can immediately be accessed by looking at a certain
index, for each class. Instead, it contains only the methods the class
overrides, and the associated index value (i.e. it is an associative
array). Like for virtual methods, the function pointer is found at
runtime, but of course, this takes longer, since it requires a search
through all indices in the DMT (I guess they are sorted, so this could
perhaps be done with a binary search) to see if the function is defined
there. If it is not, the compiler will continue with the direct ancestor,
and so on, until it is finally found. That is MUCH slower, of course.
It is still in use for functions that are not so often overridden. A left
over from the Delphi 1 and Turbo Pascal days.
BCB has extensions that allow it to use such dynamic methods as well.
--
Rudy Velthuis [TeamB] http://rvelthuis.de/
"I am ready to meet my Maker. Whether my Maker is prepared for the
great ordeal of meeting me is another matter." -- Winston Churchill. |
|
| Back to top |
|
 |
masi Guest
|
Posted: Mon Mar 13, 2006 1:03 pm Post subject: Re: DYNAMIC - overload? |
|
|
| Quote: | Those methods are not virtual or dynamic to begin with, so you cannot
override them.
|
Ok, this is the correct explanation. thanks
| Quote: | You will have to either find another way to accomplish what
you want,
|
My opinion is that may be impossible: the only virtual methods are those who
are directly involved with existing events handling, like DoGetImageIndex,
DoGetText, etc.. In effects, this seems a correct philosophy in general
terms.
| Quote: | or else you will have to edit the original Delphi source code for
TVirtualStringTree to make the methods virtual and then recompile that
component.
|
yes, this may be the solution, although not much in the spirit of object
oriented programming in my opinion
thank you for your help
masi urbano |
|
| 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
|
|