abstract method of construct

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

abstract method of construct

Post by nastasa eodor »

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: 182
Joined: Dec 18, 2018 16:37
Location: Germany, Hessdorf
Contact:

Re: abstract method of construct

Post by nastasa eodor »

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
Post Reply