Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP API Returning an Object

Status
Not open for further replies.

Irwin1985

Programmer
Feb 2, 2017
44
ES
Hi there,

Does anybody know how to return an object from a FLL? If so, please code. I tried this but doesn't work:

Code:
#include <stdio.h>
#include "pro_ext.h"
typedef struct {
[indent]char *name;[/indent]
[indent]int age;[/indent]
} person;
void ReturningObject(ParamBlk *parm)
{
[indent]person p1;[/indent]
[indent]p1.age = 34;[/indent]
[indent]Value *val;[/indent]
[indent]val->ev_type = 'O';[/indent]
[indent]val->ev_object = (long)p1;//This doesnt work :([/indent]
[indent]_RetVal(val);[/indent]
}
FoxInfo myFoxInfo[] = 
{
[indent]{"TESTOBJECT", (FPFI) ReturningObject, 0, ""}[/indent]
};
extern "C" {
[indent]FoxTable _FoxTable = {[/indent]
[indent](FoxTable *)0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo[/indent]
[indent]};[/indent]
}

A team is only pieces that you exchange until you finish the work, it is efficient, it works.
 
Yes, a VFP object will not simply just be a C struct.

I don't see how you'd be able to create a VFP object, but the API would let you pass one in and work on it, for example add properties via _SetObjectProperty() - refer to the definition, it has an add parameter to add new properties.

So what you could start with is a FLL function that accepts a parameter of type object (or maybe reference?) and then work on that.

I don't know if the old separate LCK library construction kit has more reference, but besides API functions that act on an object I also see none creating an object variable. I understand how you try Value *val, but maybe you can only create the stub empty object and need to build up the properties via _SetObjectProperty() instead of setting the ev_object property. I don't know how that would need to be initialized, neither if you directly use a Value C type nor if you use the _NewValue() function.

One way might be making use of _Execute('mynewvar = CREATEOBJECT("empty")') to create a variable and then get it from the name table index _NameTableIndex('mynewvar') even if just to find out more about how that structure looks in memory when it's just an ampty object or when you added a few properties with _SetObjectProperty()or via _Execute() of further VFP code.

At least one thing should work, you will generate variables that way that also become accessible in the FLL C++ code. Actually some of the samples work with the concept of passing in a string with a memory variable name, also the example about _NameTableIndex implementing an XRELASE function.

That should give you some things to try. I played about 2-3 times creating own FLLs, but nothing fancy, so don't expect more than these hints that from me.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Olaf,

Using _Execute() and NTI functions sounds good to me. I'll stick with it ans see if I am able to solve my problem.

Thanks!

A team is only pieces that you exchange until you finish the work, it is efficient, it works.
 
Irwin,

Are you sure you need to return an object? Could you concatenate the relevant values into a string, and return the string from the FLL?

For that matter, are you sure you need an FLL? I don't know what your ultimate goal is, but VFP has added a lot of functionality since the days when FLLs were important. It might be worth considering whether you can achieve your goal using Windows API calls or an existing ActiveX control.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

I need a FLL because of performance. I have various classes that reads a bunch of MPR files line by line (parsing) to generate an object array, then that array is readed from an activex control to finally render a menu in the screen. In VFP native code it lasts about 6 seconds (depending of how many MPR are included and its lines), but I'm sure I can reduce that time drastically by creating an FLL).



A team is only pieces that you exchange until you finish the work, it is efficient, it works.
 
What kind of menu is that and did you try to figure out what actually needs so many seconds to generate it?
Usually genmenu is turning a menu table to an mpr (PRG) and that runs in split seconds to build up a menu.

When you're using SKIP expressions they are perhaps evaluated more often than you think and you may get that fast by caching return values for the skip expressions.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I'm not sure about this, but I suspect that it is the ActiveX control (that renders the menu) that is causing the delay. There is a significant overhead in calling an ActiveX. Admittedly, that's not likely to be multiple seconds - unless you are calling it in a loop. I would guess that reading and parsing the MPRs would be extremely fast in native VFP code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ah, I missed that an ActiveX is responsible for the final menu. I assume it can render something more complex than native VFP Sysmenu and Toolbars could, maybe multi level menus, something like a ribbon or anything else more advanced.

But I wonder if you really mean mpr parsing, mpr actually is VFP code, the menu definition actually is in an MNX table.

Bye, Olaf.

Olaf Doschke Software Engineering
 
At least one thing is documented in a KB article: Passing in an object. It'll simply arrive in the parameter array &parm->p[0].val

And just like objects passed in VFP objects passed to an FLL are a reference, working on them will affect the VFP memory variable and so you have your returned object = passed in object.

Same idea working on an array passed in by reference, you may dimension it large enough to store things into it by an FLL:

And then to read in a MNX menu, here's an introduction to access a DBF in an FLL:

Olaf Doschke Software Engineering
 
well, i for one am curious about this activeX....

...guessing a ribbon or somesuch configured via VFP menus?

Any chance you can post a link or screenshot?

n
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top