News · Meetings · Jobs · Downloads · Universal Thread articles · Web articles · Conference coverages · Consultants · Blogs · FAQ · User groups · Photos · Videos
Frequently Asked Questions

ID: 8003
Created on: February 6, 2001 06:36
Updated on: April 22, 2010 21:31

How to make a collection property of VFP object
After some investigation, I managed to make a collection-like property of object. The following is a simple sample of how to organize collection-like access (rough, need to improve it to work as real collection). It is just to show an approach.

Rating:  Rate this entry
Created by: 
Vlad Grynchyshyn
Soft Serve

DEFINE CLASS coll AS custom
	Name = "coll"
	PROCEDURE a_access
		do case
			case vartype(m.nIndex1) == 'N'
				return THIS.a[m.nIndex1]
			case vartype(m.nIndex1) == 'C'
				return THIS.a[1]
			case vartype(m.nIndex1) == 'L'
				return THIS
		*To do: Modify this routine for the Access method

	PROCEDURE a_assign
		LPARAMETERS vNewVal, m.nIndex1
		do case
			case vartype(m.nIndex1) == 'N'
				THIS.a[m.nIndex1] = m.vNewVal
			case vartype(m.nIndex1) == 'C'
				THIS.a[1] = m.vNewVal
			case ISNULL(m.nIndex1)
				THIS.a[1] = m.vNewVal
Now, the following are the test commands:

oo = createobject("coll")
oo.a(1) = 5 && no error
? oo.a(1) && displays 5
? oo.a("qweqwe") && displays 5 anyway!
? oo.a.class && displays 'Coll'
? oo.a && displays 5
oo.a("qweqwe") = 1 && no error
? oo.a(1) && displays 1
oo.a.tag = '2'
? oo.a.tag && displays 2
&& Now, the main trick - allow to access objects in collection
oo.a(1) = createobject('coll')
? oo.a("qwe").class && displays 'Coll'
oo.a("qwe").a(1) = 5 && no error
? oo.a("qwe").a(1) && displays 5!

Using above approach, it is easy to make a collection property in VFP. In detail - Access method allows to access array property as object when you return object reference from the Access method. This is very significant feature that allows to organize such collection-wide methods as "Collection.Add('item')" or 'Collection.Count' or 'Cllection.Items(index)'. Guess these functions will handle some object that is not accessible from outside world by normal means, for example, restricted in this_Access method.

I hope I will enhance this idea and make a generic collection class.


Add a comment

More entries from this member

  1. 256-color icons in EXE application compiled by VFP May 28, 2002
    VFP does not support 256-color icons as project's icon (icon displayed for EXE in Windows Explorer). But 16-color icons usually looks ugly and too simplified. Here is an approach that allows organize 256-color icons for VFP EXE application. The approach is based on use of Resource Hacker application. You can download it from following URL: http://download.techworld.cz/software/resourcehacker.zip (UPDATED: original link does not work for some reason. Let me know if this one also does not ...

  2. Force positioning of text cursor by right mouse click in EditBox and RTF ActiveX controls February 8, 2002
    There is a situation often when we need some way to position a text cursor in the text of Editbox or RTF ActiveX controlwhen right click on the control. For example, we want to display a shortcut menu on right click. In menu, user select an option that insert some text into the control on place of current position. However, right click on the control does not change the text cursor position, that confuse users. It would be good to right click, cursor moves to the clicked point and then menu disp...

  3. Grid reconstruction and how to avoid it March 16, 2001
    Have you ever found a situation when your grid don't want to behave as you directed in design time? Custom controls in columns lost? Code of columns, headers or controls event not running? Read this FAQ then. Grid reconstruction behavior is a complete removing of all grid's controls and columns and creating them again using default VFP controls. This cause lose of all methods, property settings and objects in columns and all column objects, column control to display and edit data is reset to ...

  4. How to assign code to event in run-time? September 21, 2001
    In VFP there are no direct way to assign code to the method or event in run-time mode. However, some workaround is possible with use of additional, 'hook' class. The sample below describes the approach. It is possible to make it generic. The approach is very useful to catch, for example, events of the _Screen form.

  5. How to display Tool Tips for different parts of the Grid? February 1, 2002
    In VFP6 Grid value of the ToolTipText property of controls is displayed only for the entire grid or for current control when mouse is over it. Becuase there are a lot of parts in the grid, it is often useful to display tool tip for different parts separately. Unfortunately, VFP interprets grid as a single control, displayed tool tip appearance for grid is not changed immediately even when ToolTipText property is changed, until mouse is moved out of the grid and returned into the grid into requir...

  6. How to freeze (lock) a column in the grid without use of split bar February 8, 2002
    The approach is based on a simple principle. LeftColumn property of the grid represents a column that is currently the leftmost visible column in the grid with current horizontal scrolling. As we scroll the grid horizontally, this property changes. We can assign this number to the ColumnOrder property of the column we want to hold and that’s all: this.Columns(1).ColumnOrder = this.LeftColumn You can use this in the Scrolled and AfterRowColChange events of the grid. However, there is a...

  7. How to get form caption font properties October 6, 2000
    Windows form caption properties stored in the user preferences. You can change them using Windows Control Panel\Display\Appearance. To get these parameters programmatically in VFP, you can use following routine as a sample.

  8. How to make a grid appear like a list similar to list box June 20, 2001
    This article describes how to configure grid to appear as a list similar to the list box or the drop-down list of combo box. It is for appearance only. All other things are as usual for any grid. This is useful for case when need to replace list box by a grid to display more records, because listbox is slow when displaying 1000+ rows in listbox.

  9. How to make SQL Pass-Through cursor updatable April 9, 2002
    The SQLEXEC() function in VFP allows downloading of data from any data source through ODBC. Unlike remote views, SQL Pass-Through approach does not provide default (automatic) settings in the returned cursor to update data on the server after changes in the cursor at the client side. Anyway, it is possible to customize required properties to organize updating. First of all, it is recommended to read chapters about SQL Pass Through commands in the MSDN, specially, chapters that explain propert...

  10. How to organize SUM() for character field in SQL Server SELECT query September 4, 2001
    There is a little problem for query to get something like a sum() for a character field to concatenate character values from all records in the group. Here is described solution. The approach below have an limitation to max 30 records in group for concatenation. Test it if it will work for more records in group or there should be another limitation on your server, becaus ethis number is depended on SQL Server capabilities and length of the character field being concatenated.

  11. How to put grid on the form programmatically February 5, 2001
    Suggest Grid1 is a name of grid required to put onto the form, grid should contain 10 columns an display data from the MyAlias alias. Grid should contain a combo box in the second colunm with the name Combo1. Following sample routine will allow you to see a generic idea of how to put grid on the form programmatically and recreate it again when needed. You can make it as a custom method of the form and call it when needed (for example, thisform.MakeGrid or thisform.RefreshGrid).

  12. How to refresh grid properly after sorting January 26, 2001
    I have seen many questions about sorting of a grid by clicking on its header and proper refreshing of grid after sorting. There is a reliable way to sort (index) grid cursor and properly refresh the grid without change of the record number AND with very good looking. I made this in my grid class and tested it already 2 years so far.

  13. How to work with Image field type on SQL Server (binary data)? January 11, 2001
    Text field on SQL Serevr is not good to store binary data because it is not reliable and often SQL Server corrupts binary data in text field. varbinary type could be too short. There are certain difficulties to use image field on SQL Server to store and read binary data in VFP. Image field on SQL Server mapped to general field in VFP by default, causing some difficulties when using SQL Pass Through functions. The workaround idea is to try to use memo field to update data on SQL server. At ...

  14. SPT cursor fetching and progress displaying for SPT cursor downloading February 5, 2002
    SQL Pass Through commands often can take a lot of time for running and returning the result set to the client. It is often usefult to show a progress bar in case of such lengthy process. Also, FetchAsNeeded option, available for views, could be very useful for SPT cursors as well. However, how we can open SPT cursor and set FetchAsNeeded option for it? Here is a sample code for opening the cursor in "FetchAsNeeded" mode, as well as a description of approach for organizing the progress bar for...

Copyright © 1993 - 2015 Level Extreme Inc., All Rights Reserved · Telephone: 506-547-9500 Email: info@universalthread.com · Privacy & Security · Copyright · Terms & Conditions