FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour PICTURE for DATE() ?
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
PICTURE for DATE() ?
Posted: Mon Jul 17, 2023 08:46 AM
hi,
for my TGrid i have
Code (fw): Select all Collapse
function FW_Record()
return TDataRow()
to use METHOD EDIT() of CLASS TDataRow

now i like to add some PICTURE but which PICTURE for DATE to use depend on language :?:
Code (fw): Select all Collapse
oRec := FW_Record():New( aEdit, cName )

iMax := LEN( aEdit )
FOR ii := 1 TO iMax
   nPosi := ASCAN(::aBroFields, {|x| x[1] = aEdit[ii][1] })
   IF nPosi > 0
      cType  := ::aBroFields[ nPosi ] [ DBS_TYPE ]
      nLen   := ::aBroFields[ nPosi ] [ DBS_LEN ]
      nDec   := ::aBroFields[ nPosi ] [ DBS_DEC ]
      DO CASE
         CASE cType = "C" 
            cNewPic := Replicate("X", nLen)
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "N"
            IF nDec > 0
               cNewPic := Replicate("9", nLen-nDec)+"."+ Replicate("9", nDec)
            ELSE
               cNewPic := Replicate("9", nLen)
            ENDIF
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "D"
            // which PICTURE to use depend on language ?
            cNewPic := "99.99.9999"       // German Date 
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "L"
            cNewPic := "L"
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "M"
            // Memo
      ENDCASE
   ENDIF
NEXT
lEdit := oRec:Edit()
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: PICTURE for DATE() ?
Posted: Mon Jul 17, 2023 09:06 AM
By default, TDataRow's edit method automatically uses DATEFORMAT set for the application.

At the beginning of the application
Code (fw): Select all Collapse
SET DATE GERMAN
SET CENTURY ON
Then all your dates will appear as dd.mm.yyyy in the entire application.
Setting picture everytime we edit a date is waste of time and code space.\

Next, used in the right way, TDataRow and XBrowse do most of these works automatically.
I do not see any point in rewriting everything that is already there in the library.
Code (fw): Select all Collapse
oRec := TDataRow():new( cAlias, "ID,FIRST,AGE,SALARY" )
Is all that is enough and all pictures are correctly applied
Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: PICTURE for DATE() ?
Posted: Mon Jul 17, 2023 11:51 AM
hi,

thx for Answer

your Sample is for DBF so i guess FIELD AGE is Type "D"
i want to use "Record-Set" (not ADO) from TPQServer() which use a Array

when call METHOD Edit() it will "display" right but i can "input" every Type into GET
that´s why i want to use PICTURE " . . " or " / / " or " - - "

---

this is what i have now
Code (fw): Select all Collapse
LOCAL cSetdt  := SET(_SET_DATEFORMAT)

   cSetdt := STRTRAN(cSetdt,"D","9")
   cSetdt := STRTRAN(cSetdt,"M","9")
   cSetdt := STRTRAN(cSetdt,"Y","9")

      CASE cType = "D"
         cNewPic := cSetdt
         oRec:FieldPic( ii, cNewPic )
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: PICTURE for DATE() ?
Posted: Mon Jul 17, 2023 12:26 PM
Code (fw): Select all Collapse
 oRec:FieldPic( ii, cNewPic )
Use
Code (fw): Select all Collapse
 oRec:FieldPic( ii, "@D" )
TDataRow() automatically sets correct dateformt to Dates also

Note:
Picture clauses for Dates in (x)Harbour

PICTURE "@D" // Use dateformat set. (default American, i.e., 'mm/dd/yy' )
PICTURE "@E" // Force European format ( i.e., 'dd/mm/yy' ) even if the format is set to American
Regards



G. N. Rao.

Hyderabad, India
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: PICTURE for DATE() ?
Posted: Mon Jul 17, 2023 03:44 PM

Jimmy,

If i put a date in a TGET, I always change the date to a string by using DTOC().

I can give the picture to my date anyway I want and in the VALID clause, I can link a function which checks if the date is correct or not.

Afterwards, I change the string back to a date by using CTOD().

It is quite easy and it gives you the possibilities to add more controls to the valid clause.

Example: if a date you want has to be between two other days, it gives you the posibility to give a message to tell the user what's wrong.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: PICTURE for DATE() ?
Posted: Tue Jul 18, 2023 09:18 PM
hi,
nageswaragunupudi wrote:TDataRow() automatically sets correct dateformt to Dates also
as i say i use a Array which is from "Result-Set" (not ADO) of SQL Query

i don´t "see" DATEFORMAT in CLASS TDataRow
nageswaragunupudi wrote:Note:
Picture clauses for Dates in (x)Harbour
PICTURE "@D" // Use dateformat set. (default American, i.e., 'mm/dd/yy' )
PICTURE "@E" // Force European format ( i.e., 'dd/mm/yy' ) even if the format is set to American
ok, but i don´t know which DATE Setting or which Country User have
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: PICTURE for DATE() ?
Posted: Tue Jul 18, 2023 10:03 PM
i want to use "Record-Set" (not ADO) from TPQServer() which use a Array
Are you not using something like
Code (fw): Select all Collapse
oRs := oServer:Query( "select * from customer order by id" )
If so, both XBrowse and TDataRow are fully compatible with PostGre Query and we need not set anything on our own.
We can say
Code (fw): Select all Collapse
TDataRow():New( oRs ):Edit()
// or just
XEdit( oRs )
Please try again
Code (fw): Select all Collapse
buildh pgre01
in the 32-bit fwh\samples folder
ok, but i don´t know which DATE Setting or which Country User have
Use picture "@D"
Actually we do not need to give any pictue to Get object or XBrowse, they both automatically use the "@D" picture.
In the beginning of Main(), we set the required date format like
SET GERMAN.

Note: In case we propose to distribute the application world wide, we can also set date format according the locale of the PC. But that is a differnt subject.

For now, it is enough to set
Code (fw): Select all Collapse
SET DATE GERMAN
SET CENTURY ON
All functions, Gets, Browses, etc automatically use this format.
No need at all to manually provide any picture clause
Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: PICTURE for DATE() ?
Posted: Wed Jul 19, 2023 05:18 AM
hi,
nageswaragunupudi wrote:Please try again
Code (fw): Select all Collapse
buildh pgre01
in the 32-bit fwh\samples folder
ok, DATE Format are show right after
Code (fw): Select all Collapse
SET DATE GERMAN
SET CENTURY ON
but i have still Problem with ":edit()"
i can not "save" in that Sample ... something still going wrong


---
Code (fw): Select all Collapse
    TDataRow():New( oRs ):Edit()
    // or just
    XEdit( oRs )
i have to say that i´m not using XBROWSE / XBROWSER ... i want to use a TGrid()
Code (fw): Select all Collapse
  lEdit := XEdit( aEdit, cName )
aEdit Element have {FIELDname,FIELDvalue} but not "Structure" ...
did i use XEdit() wrong :?:
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: PICTURE for DATE() ?
Posted: Thu Jul 20, 2023 07:12 AM
For editing array of values with known Field Structure, please try something like this:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

local aVals := {1,"Homer","Simpson","32179 Maiden Lane","Springfield","MD",;
                   "20503-8202",SToD("19920918"),.F.,50,6000.00,;
                   "This is a test for record 1"}
local aStruct := ; 
   {{"ID","+",4,0},{"FIRST","C",20,0},{"LAST","C",20,0},{"STREET","C",30,0},;
   {"CITY","C",30,0},{"STATE","C",2,0},{"ZIP","C",10,0},{"HIREDATE","D",8,0},;
   {"MARRIED","L",1,0},{"AGE","N",2,0},{"SALARY","N",9,2},{"NOTES","C",70,0}}

local oArrData

   SET DATE GERMAN
   SET CENTURY ON

   FWNumFormat( "E", .t. )
   SetGetColorFocus()

   oArrData := TArrayData():New( { aVals }, aStruct )
   oArrData:Edit()

return nil
All picture clauses are taken care of
Regards



G. N. Rao.

Hyderabad, India
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: PICTURE for DATE() ?
Posted: Thu Jul 20, 2023 08:24 AM
hi,
nageswaragunupudi wrote:For editing array of values with known Field Structure, please try something like this:

All picture clauses are taken care of
ok thx for the Tip
greeting,

Jimmy
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: PICTURE for DATE() ?
Posted: Sat Jul 22, 2023 09:54 AM
hi,
Code (fw): Select all Collapse
   oRec := TArrayData() :New( { aValue }, aFields )
   // now "edit"
   lEdit := oRec:Edit()
YES, that work fine now :D
greeting,

Jimmy

Continue the discussion