Hi,
I have gone backwards in my knowledge of how to write simple classes, particularly the New & Create Constructor methods
I am using Harbour & Xailer 3.02.
These classes do not inherit from windows GUI classes, they are just a few vars and methods to represent a business entity.
In my code I think I want to write this ....
oCar := Car():New( "Ford, "T", 4 )
My class looks like this ....
My questions are now that we are using Harbour :
- Should all my classes non windows GUI classes inherit from TComponent so I can use the debugger on them?
- If I inherit from TComponent, I probably need a ::parent or owner?
- Do I need a New method and what should it look like?
- Do I need a Create method and what should it look like?
- When do I need a Super():Create()?
- When do I need a Destructor ... very tricky this one?
Can you suggest a simple class in Source that is a good model to use of how it should be done in 2013.
Apologies for what may be very obvious to most of you.
Regards
Chris
Attached files
In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.
Basic syntax for own classes ??
-
- Mensajes: 384
- Registrado: Mar May 01, 2007 5:49 pm
- ignacio
- Site Admin
- Mensajes: 9469
- Registrado: Lun Abr 06, 2015 8:00 pm
- Ubicación: Madrid, Spain
- Contactar:
Basic syntax for own classes ??
ChrisGillard escribió el vie, 14 junio 2013 14:54My questions are now that we are using Harbour :
>>Should all my classes non windows GUI classes inherit from
>>TComponent so I can use the debugger on them?
No, it is not necessary. I believe all the class members from non Tcomponent inherited classes are completely shown on the debugger. In case not just use the command PROPERTY instead of DATA.
>>If I inherit from TComponent, I probably need a ::parent or owner?
No. It is not necessary.
>>Do I need a New method and what should it look like?
No. You do not needed. But if you plan to use it and inherit from TComponent, then I suggest you finish the code with this line:
RETURN ::Super:New( oParent )
>>Do I need a Create method and what should it look like?
The same as above.
>>When do I need a Super():Create()?
When you want your class to execute the code from inherited classes. BTW, use '::Super'
>>When do I need a Destructor ... very tricky this one?
Almost never. We do not use it in Xailer, since we can not control WHEN that code is executed. We prefer to destroy on the Free() method.
>>Can you suggest a simple class in Source that is a good model
>>to use of how it should be done in 2013.
I suggest you take a look to Image.prg. If there is something you do not understand (sure there will be) please ask for advice.
>>Apologies for what may be very obvious to most of you.
No need to apologize. Glad to help.
Regards,
>>Should all my classes non windows GUI classes inherit from
>>TComponent so I can use the debugger on them?
No, it is not necessary. I believe all the class members from non Tcomponent inherited classes are completely shown on the debugger. In case not just use the command PROPERTY instead of DATA.
>>If I inherit from TComponent, I probably need a ::parent or owner?
No. It is not necessary.
>>Do I need a New method and what should it look like?
No. You do not needed. But if you plan to use it and inherit from TComponent, then I suggest you finish the code with this line:
RETURN ::Super:New( oParent )
>>Do I need a Create method and what should it look like?
The same as above.
>>When do I need a Super():Create()?
When you want your class to execute the code from inherited classes. BTW, use '::Super'
>>When do I need a Destructor ... very tricky this one?
Almost never. We do not use it in Xailer, since we can not control WHEN that code is executed. We prefer to destroy on the Free() method.
>>Can you suggest a simple class in Source that is a good model
>>to use of how it should be done in 2013.
I suggest you take a look to Image.prg. If there is something you do not understand (sure there will be) please ask for advice.
>>Apologies for what may be very obvious to most of you.
No need to apologize. Glad to help.
Regards,
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
-
- Mensajes: 384
- Registrado: Mar May 01, 2007 5:49 pm
Basic syntax for own classes ??
Hi Ignacio,
Thanks for your detailed reply and I am now being more successful by NOT inheriting from TComponent and using a
METHOD Init CONSTRUCTOR.
My next problem is defining an event.
The Class is a ReportField object like your RptColumn.
I am defining an OnPrintData event like yours
In my class definition I have ( same as you, but simpler for moment) .....
EVENT OnPrintData( oSender, @xString, Value )
In My Print Method, I have in PUBLISHED section .....
::OnPrintData( oSender, @xString, value )
In my test application I have .....
aFields[1]:OnPrintData := { | oSender, xString, Value | xString := "999" }
If I put a logdisplay in the block above I can see that xString & Value are correct at runtime.
But my changes to the passed by reference xString do not appear back in my Print Method .... xString & Value are unchanged.
I have studied your code and I think I am the same.
What am I doing wrong please.
Thanks
Chris
Thanks for your detailed reply and I am now being more successful by NOT inheriting from TComponent and using a
METHOD Init CONSTRUCTOR.
My next problem is defining an event.
The Class is a ReportField object like your RptColumn.
I am defining an OnPrintData event like yours
In my class definition I have ( same as you, but simpler for moment) .....
EVENT OnPrintData( oSender, @xString, Value )
In My Print Method, I have in PUBLISHED section .....
::OnPrintData( oSender, @xString, value )
In my test application I have .....
aFields[1]:OnPrintData := { | oSender, xString, Value | xString := "999" }
If I put a logdisplay in the block above I can see that xString & Value are correct at runtime.
But my changes to the passed by reference xString do not appear back in my Print Method .... xString & Value are unchanged.
I have studied your code and I think I am the same.
What am I doing wrong please.
Thanks
Chris
-
- Mensajes: 384
- Registrado: Mar May 01, 2007 5:49 pm
Basic syntax for own classes ??
!!!!! Solved It !!!!!
if I define my event as ....
EVENT OnPrintData( @xString, Value )
When I use it the oSender comes through as the first parameter automatically!
oRepFld:OnPrintData := { | oSender, xString, Value | xString := "999"
The third parameter is as expected.
So when defining an EVENT you don't need the oSender, it is added for free!
Think I'm done now.
Chris
if I define my event as ....
EVENT OnPrintData( @xString, Value )
When I use it the oSender comes through as the first parameter automatically!
oRepFld:OnPrintData := { | oSender, xString, Value | xString := "999"
The third parameter is as expected.
So when defining an EVENT you don't need the oSender, it is added for free!
Think I'm done now.
Chris
- ignacio
- Site Admin
- Mensajes: 9469
- Registrado: Lun Abr 06, 2015 8:00 pm
- Ubicación: Madrid, Spain
- Contactar:
Basic syntax for own classes ??
ChrisGillard escribió el sáb, 15 junio 2013 13:57!!!!! Solved It !!!!!
if I define my event as ....
EVENT OnPrintData( @xString, Value )
When I use it the oSender comes through as the first parameter automatically!
oRepFld:OnPrintData := { | oSender, xString, Value | xString := "999"
The third parameter is as expected.
So when defining an EVENT you don't need the oSender, it is added for free!
Think I'm done now.
Chris
That's it. Glad you solve it!
Regards,
if I define my event as ....
EVENT OnPrintData( @xString, Value )
When I use it the oSender comes through as the first parameter automatically!
oRepFld:OnPrintData := { | oSender, xString, Value | xString := "999"
The third parameter is as expected.
So when defining an EVENT you don't need the oSender, it is added for free!
Think I'm done now.
Chris
That's it. Glad you solve it!
Regards,
Ignacio Ortiz de Zúñiga
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com
[OZ Software]
https://www.ozs.es
--
[Equipo de Xailer / Xailer team]
https://www.xailer.com