Author | Topic: SCATTER() for DataObjects ? | |
---|---|---|
Hubert Brandel | SCATTER() for DataObjects ? on Wed, 15 Oct 2014 08:38:31 +0200 Hi, I use this function to read a record into an DataObject and it works, but I asked me if there is a better / build in solution for it ? function ReadRecord(nSelect) local nFC := (nSelect)->(fcount()) local o := DataObject():new() local i, cFN for i := 1 to nFC cFN := (nSelect)->(fieldName(i)) o:&(cFN) := (nSelect)->(fieldGet(i)) next return o | |
Andreas Herdt | Re: SCATTER() for DataObjects ? on Wed, 15 Oct 2014 16:37:57 +0200 Hi Hubert, No, there is no built in function doing this job. Well done. On the other hand I would expect that a built in function would look exactly the same with one additional detail: In case no workarea ordinal is passed then the parameter nSelect defaults to the currently selected workarea. ///////// snip ///////// ..... IF PCount() == 0 nSelect := Select() ENDIF ...... /////// snap ////////// Andreas Herdt Alaska Software -------------------------------------------------------------------- Technical Support: support@alaska-software.com News Server: news.alaska-software.com Homepage: http://www.alaska-software.com WebKnowledgeBase: http://www.alaska-software.com/kbase.shtm Fax European Office: +49 (0) 61 96 - 77 99 99 23 Fax US Office: +1 (646) 218 1281 -------------------------------------------------------------------- "Hubert Brandel" wrote in message news:3712e08e$19162f8d$89d4@news.alaska-software.com... > Hi, > > I use this function to read a record into an DataObject and it works, but > I asked me if there is a better / build in solution for it ? > > function ReadRecord(nSelect) > local nFC := (nSelect)->(fcount()) > local o := DataObject():new() > local i, cFN > for i := 1 to nFC > cFN := (nSelect)->(fieldName(i)) > o:&(cFN) := (nSelect)->(fieldGet(i)) > next > return o | |
Thomas Braun | Re: SCATTER() for DataObjects ? on Thu, 16 Oct 2014 08:51:04 +0200 Andreas Herdt wrote: > On the other hand I would expect that a built in function would look > exactly the same with one additional detail: In case no workarea > ordinal is passed then the parameter nSelect defaults to the currently > selected workarea. I would like to suggest the following: Encapsulate Huberts code into a class method "scatter(nSelect)" So instead of calling oData = ReadRecord() it would be oData = DataObject():Scatter() Of course we could create our own class - derived from dataobject() - for that, but an integrated and documented method is prefered. And, BTW, there could be a gather() method as well Thomas | |
Hubert Brandel | Re: SCATTER() for DataObjects ? on Sat, 18 Oct 2014 12:17:33 +0200 Am 15.10.2014 16:37, schrieb Andreas Herdt: > IF PCount() == 0 > nSelect := Select() > ENDIF I personly would prefere IF empty(nSelect) nSelect := Select() ENDIF do you see a problem with this ? | |
Andreas Herdt | Re: SCATTER() for DataObjects ? on Sat, 18 Oct 2014 19:41:30 +0200 Hi, For a numeric having the value 0 the function Empty() returns .T. Being of no practical relevance here because you will never have a workarea open having the ordinal 0, I think comparing nSelect == NIL or PCount() == 0 is more clear at this place. Andreas Herdt Alaska Software -------------------------------------------------------------------- Technical Support: support@alaska-software.com News Server: news.alaska-software.com Homepage: http://www.alaska-software.com WebKnowledgeBase: http://www.alaska-software.com/kbase.shtm Fax European Office: +49 (0) 61 96 - 77 99 99 23 Fax US Office: +1 (646) 218 1281 -------------------------------------------------------------------- "Hubert Brandel" wrote in message news:1921ed34$1eb578d$19b95@news.alaska-software.com... > Am 15.10.2014 16:37, schrieb Andreas Herdt: >> IF PCount() == 0 >> nSelect := Select() >> ENDIF > > I personly would prefere > > IF empty(nSelect) > nSelect := Select() > ENDIF > > do you see a problem with this ? > |