How to pass a function as parameter in PowerBuilder - powerbuilder

Lately, I am using PowerBuilder 12.5 for application development.
But, I don't know how to pass a function as parameter in PowerBuilder. Is it possible? and what is the Callback type of Win API.

PowerBuilder does not support callbacks or passing of functions as parameters.

Related

How to convert Automation element in to UITestControl [closed]

I came across one scenario where I have to identify object using Windows UI automation element.
I want to convert this object back to UITestControl, so that I can use inbuilt methods like waitforcontrol ready etc.
How Can I do this?
regards,
User232482
You can use one of the UITestControlFactory methods. Use UITestControlFactory.FromNativeElement Method (Object, String). You'll have to pass your UIAutomation element in the object parameter and the Technology name(Ex: "UIA") to the String method.More details are available in MSDN https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.uitestcontrolfactory.fromnativeelement.aspx

Calling Lua Functions From C++

I'm using the latest version of LuaJit and need some help getting started. What I need is to have a bunch of functions exposed to the Lua environment which can be overridden inside the scripts to run the user's supplied code, these functions would then be called during set events from within C++
For example, when the user presses their TAB key down it would call a function from the lua environment such as OnScoreboardOpen() and when the user releases their TAB key it would call the corresponding function OnScoreboardClose() these functions could be attached to a metamethod like Game or GM.
Could someone point me to some tutorials or sample code showing how this can be accomplished?
Thank you very much for your time.
Basically you use these two functions: lua_pushXXX and lua_pcall
Depends on how you name the LUA function, it can be plain function or object method.
i.e.
function OnScoreboardOpen()
end
OR
function Game:OnScoreboardOpen()
end
It's relatively simple to use plain function, just do:
// TODO: sanity check
lua_getglobal(L, name);
lua_pushnumber(L,123);
lua_pcall(...);

Accessing a geometry type database field from Delphi? [closed]

I am under a POSTGRESql database using the PosGis module and i need to access a database field from a Delphi application which is a GEOMETRY type field.
By Using a FieldByName('...').AsString, it creates me an error.
Is there a way to get this data in Text/String format from SQL or in Delphi please ?
Thanks
Gwenael
You can use PostgreSQL data type casting - SELECT ... <expression>::text ...
AFAIK there is no Delphi field type that could match, it is up to the middleware/driver used to access it to transform it into another datatype, or supply an ad-hoc class to implement the specific field behaviour. I guess the Delphi standard one doesn't - look for someone that does, or you may have to access the Postgres client API directly.

print,printto on MAC OS X

I'm trying to call printing of a document from my C++(XCode) application on MAC.I'm currently using Launch Services framework,but I didn't noticed where is printto option(flag).Is this supported by Launch Services at all?Is there some other way to do this?
Thanks,
Marko
According to Technical Note TN2082: The Enhanced Print Apple Event (in the legacy docs), you should be able to specify a keyAEPropData parameter of type kPMPrinterAEType whose value is a PMPrinter reference.
That TechNote is a bit unclear, though. It seems as though the keyAEPropData parameter carries both the print settings and the printer. The receiver can retrieve both pieces of information by coercing the parameter's "actual" value to two different types. That raises the question of whether you can specify the parameter value with just kPMPrinterAEType and have it work, or if it needs to be some other type.
Anyway, you can construct an AEDesc for the parameter and pass it in to LSOpenFromRefSpec() in the passThruParams field of the LSLaunchFSRefSpec structure.
It may help to use the Script Editor to send an enhanced print Apple Event to a test application which then dumps that event. That may clear up how exactly the parameter is constructed, so you can construct it in the same way.

How to consume WinRT IAsyncOperation* object in “native c++” environment

I have C/C++ SDK library which should be ported to Windows 8 Metro (WinRT).
Library is mostly OS-independent, but it contains some modules which interact with hardware using OS-provided APIs.
While porting it to WinRT I've decided to try to use WRL instead of C++/CX as much as possible. So right now I can create and consume most of the required WinRT objects.
But I've faced absolute obstacle while working with Async objects, provided by WinRT.
For example, I use following code to enumerate HW devices:
// create interface to "static" members of DeviceInformation class
ComPtr<IDeviceInformationStatics> DeviceInformationStatics;
HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation).Get(), &DeviceInformationStatics);
ComPtr<IAsyncOperation<DeviceInformationCollection*>> operation;
hr = DeviceInformationStatics->FindAllAsyncDeviceClass( DeviceClass_All, &operation);
At this point I have valid IAsyncOperation pointer. I thought it can be used like that:
task<ComPtr<DeviceInformationCollection*>> tsk(operation);
but I failed, because task<> constructor which accepts IAsyncOperation is declared under "#if defined(__cplusplus_winrt)" in ppltasks.h, which, in turn, depends on /ZW compiler option.
How I'm supposed to use IAsyncOperation object in this case? Actually, I only need to wait for operation to be completed.
Just in case someone else is looking for this in C++/WinRT:
auto asyncOp = someFunctionReturningIAsyncOperation();
asyncOp.Completed([](auto &&result, auto && status) {
// do whatever with result and status
});
From my C++/CX experience, what you can do is you can construct an AsyncOperationCompletedHandler<DeviceInformationCollection*> object, initialize it with a member function in your class, and assign it to the Completed property of the IAsyncOperation.
In C++/CX, you just construct the AsyncOperationCompletedHandler<> object with two parameters - this from the calling class, and a pointer-to-member to a callback method. Like this:
MyAsyncOp->Completed = ref new AsyncOperationCompletedHandler<ResultType ^>(this, &MyClass::OnDone);
where OnDone is defined thus:
void MyClass::OnDone(IAsyncOperation<ResultType ^> ^AsOp, AsyncStatus s)
{
ResultType ^Result = AsOp->GetResults();
}
I'm not sure how to call constructors in WRL. You figure this one out.
Also, the completion handler will be called on a random thread. If you need to pass something back to the UI thread, Dispatcher->RunAsync() is your friend. Most XAML classes have a Dispatcher member in them.
EDIT: now that I'm looking at samples, there seems to be a non-managed helper class called Callback that you construct around a this and a pointer-to-member. Look it up. Still not sure how to connect one to an IAsyncOperation though...
This is an old question... But in case anyone needs the answer like I did:
The MSDN documentation shows how to accomplish this in native C++. It's pretty straightforward. You initialize the WRL runtime, the object you're interested in and then create an event and callback handler that will be called when the event fires.
If the library hardware-specific module already works on Win32, I suggest you keep it that way. Install a Win32 service to interact with the hardware, and then the Metro app just needs to communicate with the service (many IPC options, such as sockets, pipes, I'm sure you can find one that works well even in the restricted Metro sandbox).
IAsyncOperation is an awaitable type, so you should you use the equivalent of await, or call it's Result property.

Resources