1

We've been plagued for years by the GetFileOpenName and GetFileSaveName functions that open Windows dialog boxes. When the user closes them, the application's current directory has changed. Afterward, anything we do with relative path is going to be messed up, and we're constantly running into issues creating datastores from PSRs and other related functionality as a result.

I have added code to many places that resets the current directory to what it was at application open, and that works- but it's really just a bandaid. Unfortunately, at this point, our application uses those functions in 500+ places- changing them all is possible, but far from ideal.

Both of those functions have up to 4 optional parameters- extension, filter, initdir, and aFlag.

The value of aFlag can be used to disable changing the current directory- this is great, and this is what we ALWAYS want to happen. I think by using the value of 64 (2 ^ (7-1)), it will stop changing the current directory.

I have overridden other native functions like TODAY() before, but that did not have any optional parameters.

The Powerbuilder documentation lists the syntax for GetFileOpenName as:

GetFileOpenName ( title, pathname, filename {, extension {, filter { , initdir { , aFlag } } } } )
GetFileOpenName ( title, pathname, filename[ ] {, extension {, filter { , initdir { , aFlag } } } } )

Is it possible to override these functions at the overall application level, so that I do not have to change 500+ places? I'm unable to figure out the syntax.

This is what I had hoped would work:

global type getfileopenname from function_object
end type

forward prototypes
global function integer getfileopenname (string title, ref string pathname, ref string filename {, string extension {, string filter {, string initdir {, long aFlag } } } } )
end prototypes

global function integer getfileopenname (string title, ref string pathname, ref string filename {, string extension {, string filter {, string initdir {, long aFlag } } } } );
return GetFileOpenName(title, pathname, filename, extension, filter, initdir, 64)
end function

However, saving this gives me this error:

appdwsrv.pbl(getfileopenname).getfileopenname.Forward Prototype Declarations.2: Error C0031: Syntax error

Is there a way to do what I want? Are optional parameters even possible to code into our own functions, or overridden versions of native functions? We've never done anything with them in Powerbuilder, as far as I know- other than call the built-in functions that have optional parameters.

1
  • 2
    I think I figured this out. I overrode the version of the functions that have all but the last argument, and had that version call the final version with all arguments, with a hard-coded 64 as the final parameter. This seems to force all calls of the functions that have less parameters through this one, and- as far as I can tell in my initial testing so far- that no longer results in our current directory getting messed up. Commented Jun 18 at 15:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.