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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to make a cursor as a property? 2

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
NL
Hi,

Is it possible to:
I've got a class company, with a property cursorCompany.

In the Company.Init:

THIS.cursorCompany = CREATEOBJECT("CURSOR")

In the Company.setCursorCompanies:

SELECT * FROM COMPANY INTO THIS.cursorCompany


The problem is that a cursor is loaded in the most lower work area, but I would like to make it so it is only possible to access the cursor within the object Company, and not from other objects.

Is that possible? And how?

Thanks,

Charl
 
Hi Charl,

You could try using a private datasession. Or create the cursor in a separate object (f.i. Form, Toolbar) that uses a private datasession and talk to this object via methods to retrieve data from and manipulate your cursor.

HTH,

Weedz
veld4663@exact.nl
 
Hi, Charl!

We already passed this limitation. Following is solution:

Make an object (usually it is Custom object). In INIT method of this object open cursor and than close it. However, if you want to hide it from other modules, just make alias name unique. This means: make a property of object that will contain the name of cursor alias. Than many commands can use this even without '&':

replace (this.cAlias + '.Field1') with ...

We made such class even with properties that duplicate cursor fields, so now it is an cursor object! You also can define methods like update, revert, requery...

You can generate an unique name using sys(3) function, for example.

Hope this helped.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Vlad,

You always impress me. Is there anything you have not done? ;-)

You might consider an FAQ for this with a simple example... say, 2 fields and method or two...

Pete
blindpete@mail.com

What your mother told you is true! You will go blind! (from moonshine anyway)
 
* Sample code of some methods of cursor object
* NOTE: here no errors tracking, its just very-very simple sample

procedure Init
lparameters pcTable && name of the table used

this.cAlais = 'A' + sys(3)
use (m.pcTable) again alias (this.cAlais) in 0

this.Refresh()
endproc


procedure Refresh
* read values from table into properties of object
local nFieldIndex, nOldArea
m.nOldArea = select(0)
select (this.cAlais)
IF eof()
scatter to aTmp BLANK
ELSE
scatter to aTmp
ENDIF
for m.nFieldIndex = 1 to FCOUNT()
this.AddProperty(field(m.nFieldIndex), aTmp[m.nFieldIndex])
endfor

select(m.nOldArea)
endproc


Procedure MoveNext && many others could be define by similar way
if !eof(this.cAlais)
SKIP IN this.cAlais
this.Refresh()
endif
endproc


Procedure Update
if !eof(this.cAlais) AND This.Valid()
local nFieldIndex, nOldArea
m.nOldArea = select(0)
select (this.cAlais)
dimension aTmp(FCOUNT())
for m.nFieldIndex = 1 to FCOUNT()
aTmp[m.nFieldIndex] = EVALUATE(Field(m.nFieldIndex))
endfor
gather from aTmp
* following should be advanced for more reliable updating
tableupdate(.T.,.T.)
select(m.nOldArea)
endif
endproc

Procedure Valid
* this is abstract procedure defined by user of this class
return .T.
endproc

Procedure Revert
* this procedure built with assumption that
* controls of form bount to properties of this object
this.Refresh
endproc



Hope this is enough for start.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Thanks Vlad,

Indeed, It is a way of handling the cursor object.

Thanks
Charl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top