Array of Forms?

Started by David Kenny, September 25, 2013, 05:22:51 AM

Previous topic - Next topic

David Kenny

I am restating a request made in another forum section. That we can have multiple instances of a single Form and it's code.

First, to be clear, any comments I make below or in my demo project that talk about strange results or incorrect behavior are referring to when I am using FF in undocumented ways.  I am in no way saying that this represents bugs in FF.  I’m only demonstrating what I have done to be able to use FF in this way successfully.

I had a need for an app much like MDI, but without having each of the forms tied to the client area of its parent.  Paul is right stating that the need for it won’t be common. But FF is almost capable of it right now.

If you invoke Form_Show  several times in a row you will get a new instance for each one.  Each instance behaves as it should for most things (barring any user code that uses the FF handle variables).  I say ‘most things’ but the only thing I have seen not work is the statusbar doesn’t anchor to the bottom of the form during a resize (except on the last form created â€" if it (the last form) hasn’t been deleted).  All other controls I have tried resize as defined. But I must admit that I’ve not tried too many.

1) Compile and run the demo project. 
2) Click on the “launch” three times.
3) Click the command button on each Child.
4) Now play around. Deselect the checkbox on any form and click the buttons again, launch another child, etc.
5) Notice: if the check is deselected, the button acts on the last child.
6) Resize each child… you will notice only the last child doesn’t lose sizing control of the status bar.

In the demo code for the child form, the lookup of the handle for the Listbox is the only on that uses the FF variables.  And only if the checkbox is cleared. This is because FF Handle variables always contain the ones for the last child form that was created.

Clear as mud?  I created the demo project to help show what is not that easy for me to say clearly. For those who have not yet tried PowerCollections, the demo also might be of interest.

David

Removed references to control ID's as they are the same for each instance of a form and cause no problems.

Elias Montoya

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Paul Squires

Quote
I say ‘most things’ but the only thing I have seen not work is the statusbar doesn’t anchor to the bottom of the form during a resize (except on the last form created â€" if it (the last form) hasn’t been deleted).  All other controls I have tried resize as defined.

Thanks for pointing out this bug. I have it fixed now. You will see the changes in the next FireFly update.
Paul Squires
PlanetSquires Software

David Kenny

#3
Maybe you were retrieving the handle differently than you do for the other controls, but I would stop short of calling it a bug.  Clearly, I was treading outside of documented FF procedures. ::)

Upon further investigation, I have found that the programmer has to segregate more than I first thought when using a form the way I am doing.  For instance, any Form routines that you might need a Static variable will have to be managed differently.  As my demo shows, I have utilized a UDT to store the instance handles for each control I will interact with.  I simply added another variable for each of the "static" variables and access them the same way.  I still have not found anything I couldn't work around to complete my project.

(edited to add a missing letter)

Paul Squires

The statusbar problem was due to the fact that I was using the HWND in the resize code so therefore only the most recently instance of the form would work. What I should have done was to use GetDlgItem(hWndform, IDC_STATUSBAR). I changed the code generation and it all works okay now.
:)
Paul Squires
PlanetSquires Software

Jim Dunn

I don't think you can get this level of support ANYWHERE ELSE!!!  Rock on Paul !!!
3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Wilko Verweij


Rolf Brandt

Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)