Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Pierre Bellisle on January 29, 2025, 03:30:52 AM

Title: Thank you
Post by: Pierre Bellisle on January 29, 2025, 03:30:52 AM
Just to say thank you for the new release 
0.7.0 2025-01-28T14:30:00
:D
Title: Re: Thank you
Post by: Charles Pegge on January 29, 2025, 08:11:57 AM
Thanks Pierre,

A few tweaks prompted by studying Josés TOM and AFX FreeBasic headers:

You can specify the legacy calling conventions thiscall and fastcall for 32bit compiling.

You can use the term declare inside a type when specifying OOP functions.

You can type int as mytype instead of using typedef.

#macro() .. #endmacro is also supported.

const as string =  has been fixed.
Title: Re: Thank you
Post by: Frank Brübach on January 29, 2025, 09:04:57 AM
Good morning.. Sounds good charles...

QuoteYou can use the term declare inside a type when specifying OOP functions.

You can type int as mytype instead of using typedef.

#macro() .. #endmacro is also supported.

const as string =  has been fixed.

Do you have Made examples for your improvements?
Title: Re: Thank you
Post by: Charles Pegge on January 29, 2025, 10:02:30 AM
const and fastcall still need further adjustment, but I will update again very soon.

const:
const as char c="abc"
print c


#macro:
#macro m(a)
 print a " ok"
#endmacro
m(99)


type .. as ..
type int as mytype
dim as mytype x
x=4.6
print x '5


#declare:
type cc
  dim as int ii
  declare function ff(int n) as int
end type
'
methods of cc
  function ff(int n) as int
    print n " ok"
  end function
end methods
'
dim as cc c
c.ff 123 '123 ok

thiscall
type cc
function ff thiscall (int a, int b, int c) as int
return a+b+c
end function
end type

dim cc c
print c.ff(1,10,100) '111

Title: Re: Thank you
Post by: José Roca on January 29, 2025, 07:07:47 PM
> You can use the term declare inside a type when specifying OOP functions.

Non OOP functions can also  be declared insde a type using the STATIC keyword.

For example, I'm finishing a class called CRichEditCtrl, that creates a subclassed Rich Edit control, and for its callback procedure I'm declaring

' // Static callback procedure
DECLARE STATIC FUNCTION CRichEditCtrlProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM, BYVAL uIdSubclass AS UINT_PTR, BYVAL dwRefData AS DWORD_PTR) AS LRESULT

What it does is that it will be called as a normal function, without passing the hidden this parameter to it. The advantage is that you have all contained inside the type declaration.


My new class creates a subclassed Rich Edit control, wraps all the Windows Rich Edit messages and will provide access to the other classes that wrap the Text Object Model interfaces.
Title: Re: Thank you
Post by: Charles Pegge on January 30, 2025, 09:10:53 AM
A further tweak is needed to support Declare static function ...

Another challenge is that o2 static functions are strongly encapsulated (along with static variables.
These are generally not visible outside the class.

However, getting the static function to provide a direct link to the outside world is the best solution, and avoids the need for a wrapper function.

declare function ptr AccessF2(int n) as int 'our interface function
'
type cc
  dim as int mi                'property
  declare function f1() as int 'method
  declare static function f2(int n) as int
end type

methods of cc
=============

dim static ii as int
'
static function f2(int n) as int, link @AccessF2 'linking to the outer function
  ii=n
  print "f2 " n
end function

function f1() as int
  print "f1 " ii
end function
'
end methods

AccessF2(123)
Title: Re: Thank you
Post by: Frank Brübach on January 30, 2025, 02:49:39 PM
The last example doesn't Work .. linker ..all Others are Working fine

' test 1) static function works
'
static function f2(int n) as int
print "test"
end function

f2(1)

'---------------------------------- //
'
' 2) doesnt work below
'
declare function ptr AccessF2(int n) as int 'our interface function
'
type cc
  dim as int mi                'property
  declare function f1() as int 'method
  declare static function f2(int n) as int
end type

methods of cc
=============

dim static ii as int

' error next line
static function f2(int n) as int, link @AccessF2 'linking to the outer function

  ii=n
  print "f2 " n
end function

function f1() as int
  print "f1 " ii
end function
'
end methods ' error 35 static ' linker found unidentified names

AccessF2(123)
Title: Re: Thank you
Post by: Charles Pegge on January 30, 2025, 03:54:29 PM
If you remove the f2 function  from the type block, it should work. But I'm posting the update later this afternoon.

The more compact version of this example requires no declarations and no separate methods block:. The compiler does the work.

declare function ptr AccessF2(int n) as int
'
type cc
  '
  dim as int mi
  dim as static int ii
  '
  static function f2(int n) as int, link @AccessF2
    ii=n
    print "f2 " n
  end function
  '
  function f1() as int
    print "f1 " ii
  end function
  '
end type

AccessF2(123)