The DataCAD Developer Network (DDN) is an online resource for information and support for DCAL® (DataCAD Applications Language) developers as well as anyone interested in creating fonts, toolbars, hatch patterns, or linetypes for use in DataCAD.
#78603 by dhs
Wed Aug 19, 2020 1:51 pm
A quirk regarding what happens when you dismiss a file dialog has become evident in the beta testing of my Shadow Analysis macro. I am using a standard Delphi TOpenDialog here, so this may be a Delphi question rather than a specific D4D question, but I am wondering if anybody can offer any suggestions or alternate way of doing things ....

I am not using any of the D4D supplied GetFlName procedures because they can't display a custom prompt (the prompt parameter is a line number referencing the DCADWIN.msg file, which makes them unusable for most macros where you would want to display your own prompt).

Although DataCAD is obviously the active window before the macro displays the file dialog, once the dialog is dismissed the previous window seems to become active (e.g. if I had a Windows Explorer window active immediately before switching to DataCAD and then execute a file dialog from my D4D macro, Windows Explorer window becomes the active window once the file dialog is dismissed (whether by pressing OK or Cancel)).

I have coded a workaround to this where I get DataCADs handle before displaying the file dialog and then I move Datacad back to the top window afterwards. This works, but the other window (Windows Explorer in the above example) flashes up briefly after exiting the file dialog and before DC becomes the top window again. My code to do this is pasted below .... Just wondering if anybody can suggest a better solution (e.g. should I pass some parameter other than Application to the TOpenDialog.Create procedure) ?

Code: Select all    dchandle := GetForegroundWindow;    // get DataCADs handle so it can be moved back to the top when file dialog exits
    openDialog := TOpenDialog.Create(Application);
    openDialog.Filter := 'Excel Files|*.xlsx|Comma Separated Values|*.csv';
    getpath (dir, pathcad);
.. <snip> ..
    openDialog.InitialDir := string(dir);
    openDialog.FileName := string(fil);
    openDialog.Title := 'Default Output File';
    res := openDialog.Execute;
    SetWindowPos(dchandle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);  // return to DataCAD ... for some reason it doesn't do this automatically
#78604 by Mark F. Madura
Wed Aug 19, 2020 2:19 pm
When I create modal dialogs I almost always use Create(nil). Have you tried that?

Here's an article on the subject I came across a while back:

TForm.Create(AOwner)
Picking the right parameter to optimize memory usage
https://www.thoughtco.com/tform-createaowner-aowner-1057563
#78605 by dhs
Wed Aug 19, 2020 2:51 pm
Thanks Mark,
Yes, using nil (as per your suggestion and the article you referenced) solves the problem.
I think I may have been aware of that at some stage in the past, but had obviously forgotten about it, so much appreciate your response.
David
#78609 by dhs
Thu Aug 20, 2020 4:09 pm
... actually, using nil in the create hasn't fixed it. Immediately after changing it to nil I tested and it was working as expected (on closing the file dialog DataCAD was the top window), but this morning it is consistently not working. I haven't changed anything since yesterday (still using nil in the create), so am at a bit of a loss to explain.
The problem is only occurring with TOpenDialog (there are a couple other forms that are created, displayed modally and then freed by the macro and the same problem does not exist with these). I can live with the issue and will put back the code that restores DataCAD to the top window unless anybody has a better suggestion ....

Who is online

Users browsing this forum: No registered users and 11 guests

About DataCAD Forum

The DataCAD Forum is a FREE online community we provide to enhance your experience with DataCAD.

We hope you'll visit often to get answers, share ideas, and interact with other DataCAD users around the world.

DataCAD

Software for Architects Since 1984