• Welcome to PlanetSquires Forums.
 

"Form" questions

Started by tom cone jr, December 26, 2008, 11:03:50 PM

Previous topic - Next topic

tom cone jr

I'm trying to understand how to pass values between forms.  Have built a simple two form project and have a few questions that I can't seem to answer from the helps or this board.


Is there a way to hide a form without closing it within FF? 


Is there a way to tell if a form is open?  i.e.  can I use a command button on form2 to pass values back to a textbox on form1, but only if that form is open?


My little project has two forms.  Neither is modal.  Form1 opens on startup.  Form2 opens from a command button on Form1.  Why does Form2 close if I close Form1?

Thanks.

-- tom

TechSupport

Hi Tom,

If your project only has two Forms then one of them must be modal (i.e. the Startup Form).

Show/Hide a Form: The following checks to see if the Form is visible. If it is then it hides the Form. If it is not visible then it shows the Form (assuming that a previous Form2_Show was already done). You could probably also use FireFly's FF_Control_ShowState function.


   If IsWindowVisible( HWND_FORM2 ) Then
      ShowWindow HWND_FORM2, %SW_HIDE
   Else
      ShowWindow HWND_FORM2, %SW_SHOWNORMAL
   End If


Quote
"Is there a way to tell if a form is open?"

You can use the api function IsWindow to determine if the Form handle is valid:


If IsWindow(HWND_FORM2) Then
....
End If


You could use the previously mentioned IsWindowVisible function to determine if the Form is currently visible on the screen.

You can pass values between Forms in a number of ways. I guess it all depends on what it is you're trying to accomplish. What kind of data are you trying to pass to the other Form? Are you simply trying to update a text field or Label depending on whether something exists on the visible Form?

How are you closing Form2? You must be using an wrong handle in your FF_CloseForm call in Form2.

Keep asking questions. That's how we all learn.  :)



TechSupport

Quote
"can I use a command button on form2 to pass values back to a textbox on form1, but only if that form is open?"

Depends on what you have named your Form and Command Button, but I'll assume that you didn't change the names for your test project.


If IsWindowVisible( HWND_FORM1 ) Then
   FF_Control_SetText HWND_FORM1_TEXT1, "This is my new text"
   ' or you could use FF_TextBox_SetText
End If




tom cone jr

Thanks, Paul.

My little two form project is coming along nicely. 

Still not clear about something.  Here's the context:

On startup Form1 opens. 
Form1 has a button that opens Form2 and passes text to a text box.
Works fine.
Now, thanks to your help, the same button also hides Form1.

A button on Form2 passes text back to a text box on Form1.
A "Close" button on Form 2 closes Form 2 and "shows" Form 1.

All is working well, and understood.

However, I'm puzzled about why the startup form is always opened MODAL, and why closing the startup form, closes the entire program.  Is this the way PowerBASIC programs work?  I feel like I'm missing something.  Perhaps you could explain further, or maybe you can point me to some reference material I could review for further details.

Thanks.

-- tom

TechSupport

Quote from: tom cone jr on December 27, 2008, 02:31:57 PM
However, I'm puzzled about why the startup form is always opened MODAL, and why closing the startup form, closes the entire program.  Is this the way PowerBASIC programs work?  I feel like I'm missing something.  Perhaps you could explain further, or maybe you can point me to some reference material I could review for further details.
Hi Tom,

The Startup Form is modal because there has to be a message pump. FireFly is designed so that the Startup Form is modal and also serves to receive the PostQuitMessage when that Form is closed. The PostQuitMessage causes the message pump to end and thereby ending the application. Without that message the Form would be removed from the screen but the message pump would continue to run causing a "phantom" process to remain in your Task Manager - something you don't want.

If you can describe the type of application you are developing then maybe I can suggest a better design rather than show/hiding the two Forms. Maybe everything can be done on one Form (the Main Form) using two Child Forms that show/hide the data you want to display. Just give me a hint on what it is you're trying to achieve and I'll pop together a quick working prototype that could help you in your learning.  :)


tom cone jr

Hello, Paul.

Thanks for the quick response.  At this point I'm trying to see how things fit together, learning how to address controls and forms in code, for example. 

My first project will be something akin to a rolodex, but instead of tracking people (or contacts), I want to track phone messages.  When I pull messages off my voicemail at work, I want to store them in a flat file instead of on paper. 

I'm imagining a form used to enter details for a single phone message.  Will need Add/Edit/Delete functionality.  Will need to be able to navigate forward and backwards through the messages.  Will need backup and restore functionality.

A second form would display the messages in a grid or browse, so that I can quickly step through the records, and then select one for viewing details.  Presumably this sequence would pass a record number, or other suitable identifier, back to the first form.

Then I will need a way to print individual messages, or possibly groups of messages (say for a an entire day or week, for example).

I figure this kind of thing would be useful in my office, and would be a good way to learn both PowerBASIC and FF.

What do you think?  Is this too ambitious for a first project?

-- tom

TechSupport

Tom, I think that is an EXCELLENT idea for a first project. You will hit on many items in programming that people question all the time. For example, dealing with data entry, validating entries, storing and retrieving data, modal/modeless Forms....

When I first read your post I immediately envisioned an application where there is two areas on a main Form. The left area would be a ListBox where the summary of all of the messages would be displayed. This would allow you to quickly see how many messages are available and also allow you to access them very fast. The right hand side of the Form would display the details of the selected message.

When it comes to Editing, I would probably present the user with a second, popup, MODAL Form. Make sure that it is modal and uses Form1 and the parent form (ie.  Form2_Show HWND_FORM1, %TRUE). You could pass the record number to edit in a variety of ways: (1) A global variable, (2) Storing the value in hidden Label or TextBox, (3) Accessing the 32-bit value that you can store in the ListBox with the message summary text. There is really no right or wrong way to do it. You need to have logic in your program that conveys to the editing Form whether it is a New record you are creating or simply Updating/Editing an existing record (maybe pass a negative record value number or set a global variable, etc...).

If you want to get fancy, you could devise a splitter bar to separate the left side ListBox from the right side message details (FireFly 3 has a built-in Splitter Control :) ).

While you're at it you could use SQLitening for the database (use Text or Blob fields for the message data).





tom cone jr

Paul, thanks for the encouragement and support.  -- tom