It is currently Wed Jul 17, 2019 6:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Module BaseClass (OOP)
PostPosted: Fri Apr 12, 2019 2:22 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 488
Location: Germany / one of the fishheads
mk-soft wrote:
BaseClass extended version
No longer supported.
The only difference was that the method names were saved.
Last edited by mk-soft on Sun Apr 07, 2019 1:41 pm, edited 9 times in total.


Hello mk-soft,
do I understand correctly that there is only the small version left?
I only ask because then I can clean up my code templates and delete the big version.

Regards, Kurzer

_________________
PB 5.62, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 51y
"Happiness is a pet." | "Never run a changing system!"


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Fri Apr 12, 2019 6:56 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
There shouldn't be any problems.

But it may be that I annoyed you, because now the interface name for ClassExtends is entered when inheriting a class.
This is because now the interface name is used to manage the classes, and no longer the module name.

If you have any problems, please contact us directly as PM.

On my WebSpace is still the small version v1.09, where the module name is used for the internal management.

P.S.
I'm also not sure it was a good idea to change the management from module name to interface name!

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Wed May 01, 2019 4:36 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
Update v1.11
- Change Debug Output CheckInterface

New Example own ButtonColorGadget
Code:
;-TOP
; Comment : Object ButtonColorGadget Number 42 ;)
; Author  : mk-soft
; Version : v1.04
; Create  : 01.05.2019

; OS      : All

; Link BaseClass : https://www.purebasic.fr/english/viewtopic.php?f=12&t=64305
IncludeFile "Modul_BaseClassSmall.pb"

EnableExplicit

; *****************************************************************************

DeclareModule ButtonColorGadget
 
  UseModule BaseClass
 
  Interface iButtonColorGadget Extends iBaseClass
    Resize(x, y, Width, Height)
    SetText(Text.s)
    SetFont(FontID)
    SetColor(ColorType, Color)
    GetID()
    GetText.s()
    GetColor(ColorType)
  EndInterface
 
  UnuseModule BaseClass
 
  Declare Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
 
EndDeclareModule

Module ButtonColorGadget
 
  EnableExplicit
 
  UseModule BaseClass
 
  NewClass(iButtonColorGadget)
 
  Structure sButtonColorGadget Extends sBaseClass
    Gadget.i
    ; Params
    x.i
    y.i
    Width.i
    Height.i
    Text.s
    FrontColor.i
    BackColor.i
    Flags.i
    ; Data
    Image.i
    FontID.i
    LineColor.i
  EndStructure
 
  ; ----
 
  Procedure DrawButton(*this.sButtonColorGadget)
    With *this
      If ImageWidth(\Image) <> \Width Or ImageHeight(\Image) <> \Height
        FreeImage(\Image)
        \Image = CreateImage(#PB_Any, \Width, \Height, 32)
      EndIf
      If StartDrawing(ImageOutput(\Image))
        Box(0, 0, \Width, \Height, \LineColor)
        Box(1, 1, \Width - 2 , \Height - 2, \BackColor)
        DrawingFont(\FontID)
        DrawText(\Width / 2 - TextWidth(\Text) /2, \Height / 2 - TextHeight(\Text) / 2, \Text, \FrontColor, \BackColor)
        StopDrawing()
        SetGadgetAttribute(\Gadget, #PB_Button_Image, ImageID(\Image))
      EndIf 
    EndWith
   
  EndProcedure
 
  ; ----
 
  Procedure SetText(*this.sButtonColorGadget, Text.s)
    With *this
      \Text = Text
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetText)
 
  ; ----
 
  Procedure SetFont(*this.sButtonColorGadget, FontID)
    With *this
      \FontID = FontID
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetFont)
 
  ; ----
 
  Procedure SetColor(*this.sButtonColorGadget, ColorType, Color)
    With *this
      Select ColorType
        Case #PB_Gadget_FrontColor
          \FrontColor = Color
        Case #PB_Gadget_BackColor
          \BackColor = Color
        Case #PB_Gadget_LineColor
          \LineColor = Color
      EndSelect
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(SetColor)
 
  ; ----
 
  Procedure Resize(*this.sButtonColorGadget, x, y, Width, Height)
    With *this
      ResizeGadget(\Gadget, x, y, Width, Height)
      If x <> #PB_Ignore
        \x = x
      EndIf
      If y <> #PB_Ignore
        \y = y
      EndIf
      If Width <> #PB_Ignore
        \Width = Width
      EndIf
      If Height <> #PB_Ignore
        \Height = Height
      EndIf
      DrawButton(*this)
    EndWith
  EndProcedure : AsMethode(Resize)
 
  ; ----
 
  Procedure GetID(*this.sButtonColorGadget)
    ProcedureReturn *this\Gadget
  EndProcedure : AsMethode(GetID)
 
  ; ----
 
  Procedure.s GetText(*this.sButtonColorGadget)
    ProcedureReturn *this\Text
  EndProcedure : AsMethode(GetText)
 
  ; ----
 
  Procedure GetColor(*this.sButtonColorGadget, ColorType)
    Protected color
    With *this
      Select ColorType
        Case #PB_Gadget_FrontColor
          color = \FrontColor
        Case #PB_Gadget_BackColor
          color = \BackColor
        Case #PB_Gadget_LineColor
          color = \LineColor
      EndSelect
      ProcedureReturn color
    EndWith
  EndProcedure : AsMethode(GetColor)
 
  ; ----
 
  Procedure Initialize(*this.sButtonColorGadget)
    Protected result
   
    With *this
      result = ButtonImageGadget(\Gadget, \x, \y, \Width, \Height, 0, \Flags)
      If result
        If \Gadget = #PB_Any
          \Gadget = result
        EndIf
        \FontID = #PB_Default
        \LineColor = #Gray
        \Image = CreateImage(#PB_Any, \Width, \Height, 32, #Gray)
        DrawButton(*this)
      EndIf
    EndWith
  EndProcedure : AsInitializeObject(Initialize)
 
  ; ----
 
  Procedure Dispose(*this.sButtonColorGadget)
    With *this
      If \Image
        FreeImage(\Image)
      EndIf
      If IsGadget(\Gadget)
        FreeGadget(\Gadget)
      EndIf
    EndWith
  EndProcedure : AsDisposeObject(Dispose)
 
  ; ----
 
  Procedure Create(Gadget, x, y, Width, Height, Text.s, FrontColor, BackColor, Flags = 0)
    Protected *object.sButtonColorGadget
   
    With *object
      AllocateObject(*object, sButtonColorGadget)
      If *object
        \Gadget = Gadget
        \x = x
        \y = y
        \Width = Width
        \Height = Height
        \Text = Text
        \FrontColor = FrontColor
        \BackColor = BackColor
        \Flags = Flags
      EndIf
      InitializeObject(*object)
      ProcedureReturn *object
    EndWith
  EndProcedure
 
  ; ----
 
  CheckInterface()
 
EndModule

; *****************************************************************************

;- Example

CompilerIf #PB_Compiler_IsMainFile
 
  Enumeration Windows
    #Main
  EndEnumeration
 
  Enumeration Gadgets
    #Button
  EndEnumeration
 
  Enumeration Status
    #MainStatusBar
  EndEnumeration

  LoadFont(0, "Courier New", 20, #PB_Font_Bold)
 
  Procedure Main()
    ; Define button object
    Protected btn.ButtonColorGadget::iButtonColorGadget
    Protected btnID
     
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 480, 320, "Object ButtonColorGadget Number 42 ;)" , #PB_Window_SystemMenu)
      btn = ButtonColorGadget::Create(#Button, 10, 10, 120, 30, "My Button", #Yellow, #Red)
     
      btnID = btn\GetID()
     
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Break
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #Button
                If GadgetWidth(#Button) <= 120
                  btn\Resize(#PB_Ignore, #PB_Ignore, 240, 60)
                  btn\SetText("My Big Button")
                  btn\SetFont(FontID(0))
                  btn\SetColor(#PB_Gadget_BackColor, #Green)
                  btn\SetColor(#PB_Gadget_FrontColor, #Black)
                  btn\SetColor(#PB_Gadget_LineColor, #Red)
                Else
                  btn\Resize(#PB_Ignore, #PB_Ignore, 120, 30)
                  btn\SetText("My Button")
                  btn\SetFont(#PB_Default)
                  btn\SetColor(#PB_Gadget_BackColor, #Red)
                  btn\SetColor(#PB_Gadget_FrontColor, #Yellow)
                  btn\SetColor(#PB_Gadget_LineColor, #Gray)
                EndIf
            EndSelect
           
        EndSelect
      ForEver
     
      btn\Release()
     
    EndIf
   
  EndProcedure : Main()
 
CompilerEndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Wed May 01, 2019 6:46 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
Update v1.12
- Change CheckInterface

Now better debugging information

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Wed May 01, 2019 6:51 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 11, 2006 12:07 am
Posts: 488
Location: Germany / one of the fishheads
Wohoo I can't keep up with updating your module files on my hard drive.
As we say in German: It comes stroke on stroke, like baking pretzels. :-D LOL

_________________
PB 5.62, OS: Windows 7 Pro x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age: 51y
"Happiness is a pet." | "Never run a changing system!"


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Fri May 03, 2019 4:26 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
Update v1.13
- Optimize CheckInterface

I once encapsulated the debugger function CheckInterface in a procedure and optimized it.

This is only included in the program with the debugger switched on and should always be called at the end of the module to avoid errors when assigning the methods for the interface.


P.S. Update all examples

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Sun May 05, 2019 2:50 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
Description of the module BaseClassSmall

Link: viewtopic.php?f=12&t=64305#p478264

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Module BaseClass (Module as Object)
PostPosted: Sat May 11, 2019 2:04 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1758
Location: Germany
Update descriptions

The smallest module to create an object with Purebasic. :wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye