Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show a missing browse window. 1

Status
Not open for further replies.

MrDataGuy

Programmer
Oct 18, 2010
231
US
OK folks I am embarrassed to even ask this question, I know I am missing some so obvious, but I am driving myself nuts and I am hoping someone take mercy on me, but go head and poke fun at me I deserve it (but you still need to provide an actual working answer <smile>)

Here is the situation, I want the user to click on a form button and browse a table (really a readonly SQL cursor result). Simple enough right? just do:

Code:
Select qTable
Browse normal

Well no that does not work, e.g. the browse window is not show and the application ‘freezes’ as it waits for the user to close the none-visible browse.

FYI: the code is in the click method of a button on a visual container class which is added to a page frame at runtime which is on a form.

Now here comes what I think is the important bit, the form’s WindowTYpe is MODAL and SHOWWINDOW = 1 (In Top level Form) e.g. this is MDI application. As I type this I wonder if the MODAL setting is the biggest issue, but I think I need the MODAL setting for other reasons.

Anyhow I have been trying to find a solution by throwing the kitchen sink at the problem. Here is the latest of a long string of code attempts.

Code:
Window_Title = [This is a test]
DEFINE WINDOW wBrowse FROM 20,20 TO 44,80;
CLOSE GROW COLOR SCHEME 10;
       FONT 'Courier', 12 FLOAT MDI ;
       ZOOM NONE TITLE Window_Title
	
ACTIVATE WINDOW wBrowse IN SCREEN top
BROWSE WINDOW wBrowse
DEACTIVATE WINDOW wBrowse
RELEASE WINDOW wBrowse

When I do a SET STEP ON and debug I can see that the running application holds on the BROWSE WINDOW wBrowse line of code.

Bottom line question: What code do I need to allow the user to see the information via a browse?
 
You're right. The problem is that your form is modal.

Two solutions come to mind:

1. Don't do a browse. Instead, add a page to the form, place a grid on that page, and programmatically switch to that page when the user wants to see the table.

2. Don't have a modal form. Instead, make it a top-level form, and hide the main VFP window. Open the browse in a separate top-level window.

Personally, I would go for option 1.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
My solution:
(Mike thanks for the ideas.)

I bit the bullet and created a form with a grid and an OK button to simulate a browse. Nice thing about this solution is that I can later add some features to the form like counts of records or a button to export the information to a CSV or…. I created it as a visual form (vs all in code) below are some code fragments to help those who run into this issue in the future. (BTW in this application there are many datasessions so I need to pass which datasession of interest is needed.)

Calling code:
Code:
USE C:\DATA\MyData.DBF
DO FORM frmBrowse WITH [MyData], SET( [DataSession] )

Misc code and properties fragments in the form:
Code:
	Form Props:
	Height 	= 426
	Width 	= 713
	ShowWindow 	= 1
	DoCreate 	= .T.
	AutoCenter 	= .T.
	Caption = ""
	Icon 	= graphics\booking.ico
	WindowType = 1
	Name = "frmbrowse"
	
	Grid Props:
	Anchor = 15
	Height = 384
	Left = 0
	ReadOnly = .T.
	Top = 0
	Width = 720
	Name = "Grid1"
	
	PROCEDURE Init
		LPARAMETERS pCursor, pDataSession

		SET DATASESSION TO pDataSession
		This.grID1.RecordSource = pCursor
	EndProc
 
Looks like a good solution. In general, a grid is better than a browse, if only because it fits in better with the object-oriented way of doing things. Plus you can place it pretty well wherever you want; you don't have the issue of showing it in its own window, like a browse.

Thanks for sharing your code.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Using a grid is the way to go IMHO. You could as well use a browse as a grid.
If you set your form's (the one that hosts the grid) Desktop property to .t. then you would get a floating modal form. That may be more appropriate to use. ie:
Code:
*BrowseForm.prg
LPARAMETERS tcAlias
LOCAL loForm
loForm = CREATEOBJECT('MyBrowseForm',m.tcAlias)
loForm.Show()

define class MyBrowseForm as Form
  Height=400
  Width=600
  ShowWindow=1
  WindowType=1
  Desktop =.t.
  
  Add object myGrid as Grid with ;
    height=400,width=600,anchor=15

  PROCEDURE Init(tcAlias)
  	this.myGrid.Recordsource = m.tcAlias
  endproc    
enddefine

You could use it like a browse.
Code:
select * from (_samples+'data\Customer') ;
  where Country like 'U%' ;
  into cursor xx nofilter

BrowseForm('xx')



Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top