Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jun Tangunan
  Where is Jun Tangunan?
 Cabanatuan
 Philippines
 Jun Tangunan
 To: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 Tags
Subject: RE: I have Little proble with Class
Thread ID: 248740 Message ID: 248962 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Classes and Objects
Date: Saturday, December 26, 2009 4:20:04 AM         
   


> > Thanks Stefan,
> >
> > Problem Solved...
>
> You're welcome.
>
> FWIW, if you are interested, there are a few things that I'd suggest to do differently:
>
> For one, if you'd use a Grid.RecordSource / Requery approach that would not cause "grid reconstruction", you'd get rid of a reasonable amount of code, so that maintenance would get easier.
> For instance, a Grid.RecordSourceType=4 or type=1 with Parameterized Local View as the RecordSource would work more smoothly: if the latter had a Where condition like "... Lower(theCharField) Like ?m.theParameter ...", your searchbox.InterActiveChange() would boil down to two or three lines (full example pasted below), e.g. in pseudo code
>
> Local tcParameter
> tcParameter = Lower(Trim(NVL(This.Value,''))) + '%'
> Requery('yourView')
> 

>
> Secondly, the content of methods is a little mixed: As soon as you begin calling "events", like your textbox.KeyPress() code being occasionally calling This.InterActiveChange(), that usually means that methods contain things that should be separated.
> Or in other words, one particular method should usually have one particular purpose, as opposed to mixing different purposes and doing "all in one".
> In your case, for instance a separate RequeryTheGrid() method would probably improve the construction.
>
> Thirdly, the string-to-objects approach leading to ¯o commands is less readable and safe, more difficult to debug, and requires additional resources at runtime. So that an improvement would probably be to change something like this:
>
> * your code
> Local Objvar,vsb,setfcs
> Objvar  = "thisform."+This.lstobj+".visible"
> setfcs  = "thisform."+This.lstobj+".setfocus"
> &Objvar = .T.
> &setfcs  
> 
> * better:
> Local loGrid as Grid
> loGrid = GetPem("thisform."+This.lstobj)
> loGrid.Visible = .T.
> loGrid.SetFocus()
> && ToDo: add "defensive" checks, PemStatus(), VarType(), perhaps even Try/Catch, "Assert" assumptions
> 

>
>
> hth
> -Stefan
>
>
>
> * Grid / Parameterized View Example -
> * most of the code is for the demo setup, opening the Vfp "test data" example,
> * and creating our own temp database/view.
> * So the core functionality boils down to the PROCEDURE txtSearch.InteractiveChange():
> 
> LOCAL oForm as Form
> oForm = CREATEOBJECT('TestForm')
> oForm.Show(1)
> RETURN
> 
> DEFINE CLASS TestForm as Form
> 	Width = 800
> 	Height = 600
> 	AutoCenter = .T.
> 	DataSession = 2 && private DS
> 	cTempDB = ADDBS(GETENV("TEMP"))+'testDB.dbc'
> 
> 	PROCEDURE Load
> 		OPEN DATABASE HOME(2)+'data\testdata' SHARED
> 		CREATE DATABASE (This.cTempDB)
> 		SET DATABASE TO testDB
> 		CREATE VIEW vTest as ;
> 			Select * From testdata!customer ;
> 			Where ;
> 				UPPER(cust_id) Like ?tcParameter OR ;
> 				UPPER(company) Like ?tcParameter OR ;
> 				UPPER(contact) Like ?tcParameter
> 		USE testDB!vTest IN 0 NODATA
> 	ENDPROC
> 
> 	PROCEDURE Unload
> 		CLOSE DATABASES ALL
> 		#if VERSION(5) >= 800
> 		TRY
> 		#endif
> 			ERASE ( FORCEEXT(This.cTempDB, '*') )
> 		#if VERSION(5) >= 800
> 		CATCH
> 		ENDTRY
> 		#endif
> 	ENDPROC
> 
> 	ADD OBJECT txtSearch as Textbox WITH Left = 10, Top = 10
> 	PROCEDURE txtSearch.InteractiveChange()
> 		LOCAL tcParameter
> 		tcParameter = '%' + UPPER(ALLTRIM(NVL(This.Value,''))) + '%'
> 		REQUERY('vTest')
> 	ENDPROC
> 
> 	ADD OBJECT grdTest as Grid WITH ;
> 		Left = 10, Top = 50, Width = 780, Height = 540, ;
> 		Anchor = 15, AllowCellSelection = .F., RecordSource = 'vTest'
> ENDDEFINE
> 



Hello Stef,

That is a very impressive sample. :-)

Jun Tangunan
http://weblogs.foxite.com/sandstorm36/default.aspx
http://www.coderisland.com/forum/viewforum.php?f=10

ENTIRE THREAD

I have Little proble with Class Posted by Neeraj Charne @ 12/22/2009 7:48:22 PM
RE: Stefan...i have Little proble with Class Posted by Stefan Wuebbe @ 12/23/2009 10:29:51 AM
RE: Stefan...i have Little proble with Class Posted by Neeraj Charne @ 12/23/2009 6:30:40 PM
RE: I have Little proble with Class Posted by Stefan Wuebbe @ 12/23/2009 6:57:22 PM
RE: I have Little proble with Class Posted by Neeraj Charne @ 12/23/2009 8:55:47 PM
RE: I have Little proble with Class Posted by anand kulkarni @ 12/24/2009 3:58:32 AM
RE: I have Little proble with Class Posted by Neeraj Charne @ 12/25/2009 10:58:07 AM
RE: I have Little proble with Class Posted by anand kulkarni @ 12/26/2009 1:03:18 PM
RE: I have Little proble with Class Posted by Stefan Wuebbe @ 12/24/2009 8:42:59 AM
RE: I have Little proble with Class Posted by Neeraj Charne @ 12/25/2009 11:15:47 AM
RE: I have Little proble with Class Posted by Jun Tangunan @ 12/26/2009 4:20:04 AM
RE: I have Little proble with Class Posted by Stefan Wuebbe @ 12/26/2009 8:34:21 AM
RE: I have Little proble with Class Posted by vivek deodhar @ 12/30/2009 6:15:42 AM
RE: I have Little proble with Class Posted by Stefan Wuebbe @ 12/30/2009 9:30:32 AM