abstract method of construct

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
nastasa eodor
Posts: 157
Joined: Dec 18, 2018 16:37
Location: Germany, Hessdorf
Contact:

abstract method of construct

Postby nastasa eodor » Sep 14, 2021 16:23

some one ask for that, here is one of solution, enjoy

Code: Select all

type TObject extends object
    declare abstract operator cast as any ptr
    declare abstract sub Create
end type

type TFrame extends TObject
    declare virtual operator cast as any ptr
    declare virtual sub Create
    declare constructor
    declare destructor
end type

type TForm extends TFrame
    declare virtual operator cast as any ptr
    declare virtual sub Create
    declare constructor
    declare destructor
end type

operator TFrame.cast as any ptr
    return @this
end operator

sub TFrame.Create
    ? "call Frame constructor"
end sub

constructor TFrame
    Create
end constructor

destructor TFrame
    ? "call Frame destructor"
end destructor

operator TForm.cast as any ptr
    return @this
end operator

sub TForm.Create
    ? "call Form constructor"
end sub

constructor TForm
    Create
end constructor

destructor TForm
    ? "call Form destructor"
end destructor

''''''''''''''''
dim as TFrame Fr
dim as TForm F

sleep
nastasa eodor
Posts: 157
Joined: Dec 18, 2018 16:37
Location: Germany, Hessdorf
Contact:

Re: abstract method of construct

Postby nastasa eodor » Sep 14, 2021 16:40

ANONYMOUS CALLING OF FORM CREATION

Code: Select all

type TObject extends object
    declare abstract operator cast as any ptr
    declare abstract sub Create
end type

type TFrame extends TObject
    declare virtual operator cast as any ptr
    'declare virtual sub Create
    'declare constructor
    declare destructor
end type

type TForm extends TFrame
    declare virtual operator cast as any ptr
    declare virtual sub Create
    declare constructor
    declare destructor
end type

operator TFrame.cast as any ptr
    return @this
end operator

/'sub TFrame.Create
    ? "call Frame constructor"
end sub

constructor TFrame
    Create
end constructor'/

destructor TFrame
    ? "call Frame destructor"
end destructor

operator TForm.cast as any ptr
    return @this
end operator

sub TForm.Create
    ? "call Form constructor"
end sub

constructor TForm
    Create
end constructor

destructor TForm
    ? "call Form destructor"
end destructor

''''''''''''''''
'dim as TFrame Fr
dim as TForm F

'ANONYMOUS CALLING OF F
dim as TFrame ptr FR=new TYPEOF(F)

sleep

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 5 guests