|
FORUMS PROFESSIONNELS WINDEV, WEBDEV et WINDEV Mobile |
| | | | | |
Base class uses method from derived class |
Débuté par Paulus604, 24 juil. 2020 21:58 - 4 réponses |
| |
| | | |
|
| |
Membre enregistré 4 messages |
|
Posté le 24 juillet 2020 - 21:58 |
Hi, as I am new with WinDev I encounter next challenge: in Base Class I made a void method, eg : HEADER I need the Base Class to use the actual method from the derived Class, also named HEADER,
So in Base and Derived Class I wrote (but his doesn't work): MakeDoc is Class ... procedure virtual HEADER( ) // no code ... procedure AddPage( ) ... Header( ) // at this place the method of the derived class need to be used .... ================= Derived Class: ActualDoc is MakeDoc ... Procedure HEADER( ) // actual Method to be used by base class AddPage() !! Trace("making header") ... ActualDoc.Addpage( )
(Normally you override a Base-Method from the Derived Class, with a method IN the derived class. Here I need to override a Base-Method within the Base Class, with a method IN the derived class.) Thanks Paul |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 123 messages Popularité : +7 (9 votes) |
|
Posté le 04 août 2020 - 17:45 |
Hi Paulus
There are some issues with your declarations... And I think that what you want to do doesn't make any sense design wise. Why would you want to force a method in a derived class from the base class? Conceptually this doesn't make any sense but I think it can be done either by interfaces or by declaring the derived class in the base class which completely bullocks I guess...
This is how this should be designed where you instantiate the class that you want to run the method for...
MakeDoc is Class VIRTUAL Procedure Header() VIRTUAL Procedure AddPage()
ActualDoc is Class inherits MakeDoc Procedure Header() Procedure AddPage()
DocVar is ActualDoc DocVar.Header()
-- Peter Holemans www.mcs2.eu www.pixontri.eu |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 4 messages |
|
Posté le 18 août 2020 - 22:38 |
Hello Peter, Thanks for your input. I will try to explane more: I'm rewriting code from Visual Objects (C++ ish) to Windev. In VO it works: Method HEADER()/FOOTER() as void pascal Class MakeDoc. In ActualDoc I create method HEADER()/FOOTER() with code of the base class (Like CELL / SETFONT / LINE / SETX / ..). In the method AddPage() I need to paste (somewhere on top and in the middle) the code from FOOTER and HEADER. So, if I ripp out Addpage, I need to be very carefull with the code, because most variables are global in the Base class. The only methods from outside class MakeDoc are Header and Footer! Also splitting up AddPage is not recommendable, because of these local variables. If I do so, calling a method from MakeDoc fails (error).
The cleanest way is to give priority to ActualDoc.Header, instead of MakeDoc.Header. I would think the VIRTUAL declaration would do the trick. Why else "Virtual"?
What I see in ProjectExplorer: HEADER and FOOTER having also a V in the icon ????? How can I get remove that?
I Hope I made it somewhat more clear what I need to make..: making ACTUALDOC.HEADER() visible.
---------------------------------------------- IN MAKEDOC (base)
Procedure PUBLIC AddPage() LOCAL l_family, l_style, l_dc, l_fc, l_tc is string l_size, l_lw is real l_cf is boolean
l_family = m_sV_fontfamily l_style = m_sV_fontStyle l_size = m_rV_fontsizept l_lw = m_rV_linewidth l_dc = m_sV_drawcolor l_fc = m_sV_fillcolor l_tc = m_sV_textcolor l_cf = m_bV_colorflag IF m_nxV_page>0 THEN m_bV_infooter = True FOOTER() m_bV_infooter = False _endpage() END
_beginpage()
_out("2 J")
_out(_fmtreal(l_lw, 4) + " w")
IF Length(l_family) > 0 THEN Setfont(l_family,l_style,l_size) END
IF l_dc <> "0 G" _out(l_dc) END IF l_fc <> "0 g" THEN _out(l_fc) END m_sV_textcolor = l_tc m_bV_colorflag = l_cf
HEADER()
IF m_rV_linewidth <> l_lw m_rV_linewidth = l_lw _out(_fmtreal(l_lw, 4) + " w") END
IF Length(l_family) > 0 THEN Setfont(l_family, l_style, l_size) END
IF m_sV_drawcolor <> l_dc THEN m_sV_drawcolor = l_dc _out(l_dc) END IF m_sV_fillcolor <> l_fc THEN m_sV_fillcolor = l_fc _out(l_fc) END m_sV_textcolor = l_tc m_bV_colorflag = l_cf
--------------------------------------- IN ACTUALDOC (derived):
Procedure HEADER() Trace("header in uitvoering") Cell(190,12,"KOPSTUK",0,1,"C")
Procedure Footer() Trace("footer in uitvoering") Cell(190,12,"VOETSTUK",0,1,"C") |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 4 messages |
|
Posté le 25 août 2020 - 22:36 |
Meanwhile in the Netherlands..... Problem solved! As I was used to instantiate direct form a class and add the overload method there, in Windev you need an extra step. So: MakeDoc is class //[base]; here you find Virtual Header and Virtual Footer
AllmostDoc is class inherits from Makedoc //[derived]; overload the methods HEADER and FOOTER here
ActualDoc is AllmostDoc //[instantiated] // ... add the rest of the programm using the base-class methods, like: ActualDoc.Cell(....) or ActualDoc.Output(..)
Thanks all! |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 4 messages |
|
Posté le 25 août 2020 - 22:38 |
As mentioned by Peter! I Almost forgot... |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|