Posts: 69
Threads: 19
Joined: Dec 2005
Yet another question i have :lol: (this time i want to implement this)
"How do you declare and use function pointers in user-defined types?"
Example:
struct {
,int a;
,function* pfunc;
,ARRAY(function*) apfunc;
} var;
I want to assign the address of some function, user-defined classmember of some class, to
var.pfunc and/or
var.apfunc[i], and then use that variable to call the assigned function.
How would i do this all?
I searched in help but only reference i could find was using callback functions for pre-made functions, which didnt cover my question enough for me to use it myself.
Only relevant part was that you can get function adress using &, but not how to declare and use it for self...
Well thats all for now, 3M
Posts: 12,065
Threads: 140
Joined: Dec 2002
You can get address of dll and userf-defined functions. Cannot get member function address. Assign to int (QM does not check function type). Call using
call.
int fa=&Function2
;...
call fa a1 a2
Posts: 69
Threads: 19
Joined: Dec 2005
hmm ok thank you...
Im somehow troubled that you can not get address of member functions
Are you sure its imposible even within same class?
This is going to make me think everything over again, to implement differently...hmmm bah.
*edit*
Ohh and when you use call, will the function still be called in same instance and thread as caller or will it start a new?
I was hoping on usage like: fa(a1,a2)
without need for call or similar...
Well thats all for now, 3M
Posts: 69
Threads: 19
Joined: Dec 2005
Im still strugling with this....
How can i make a smart dialog as a member function?
Because
ShowDialog needs the address of the function itself which calls
ShowDialog inside itself...
Example inside function cJobSystem.ShowSplash:
if(!ShowDialog(dd &this.ShowSplash &controls 0 2)) ret
this gives: "Error in cJobSystem.ShowSplash: expected variable or function name."
Well thats all for now, 3M
Posts: 12,065
Threads: 140
Joined: Dec 2002
Dialog function is called directly by Windows. Windows cannot call member functions because it does not know the variable. Use intermediate UDF that retrieves variable address and calls member function.
Macro
class ClassDlg a
ClassDlg cd
cd.ShowDlg
Member function ClassDlg.ShowDlg
str controls = "4"
str c4Che
if(!ShowDialog("ClassDlg_DlgProc" &ClassDlg_DlgProc &controls 0 0 0 0 &this)) ret
Member function ClassDlg.DlgProc
function# hDlg message wParam lParam
;messages
sel message
,case WM_INITDIALOG ;;don't call DT_InitDialog!
,ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3 mes "Button"
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1
Function ClassDlg_DlgProc
;\Dialog_Editor
function# hDlg message wParam lParam
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Button 0x54032000 0x0 10 10 48 14 "Button"
;4 Button 0x54012003 0x0 170 10 48 12 "Check"
;END DIALOG
;DIALOG EDITOR: "" 0x2010900 "" ""
if(message=WM_INITDIALOG) DT_Init(hDlg lParam)
ClassDlg* p=+DT_GetParam(hDlg)
if(p) p.DlgProc(hDlg message wParam lParam)
Posts: 69
Threads: 19
Joined: Dec 2005
Thank you, i will be studiying this a bit more until fully understand whats happening.
But there are more commands that use a callback function, so the unability to get member-functions address is actualy breaking your whole class + member-function functionality...
Using what you did above is actualy placeing the whole functionality, of what the coder intended tobe inside a class, outside the whole class programming.
Thus making QM not able tobe used for Object-Oriented programming.
I realy hope you will implement this short comming someday...
(taking and using member function addresses)
Well thats all for now, 3M
Posts: 12,065
Threads: 140
Joined: Dec 2002
QM language is intended to create automation-related functions that are not built into QM. I think a macro program does not need to support such things as member function address. Function addresses usually are used with Windows API functions, but you cannot use address of member function with Windows API functions, in any language. In C++ you could use address of static member function. QM does not support static member functions, but you can hide functions by placing them into private folders or prepending two underscores to the name. You can also give some unique name, eg ClassName_FunctionName.