1

Konu: Kodu gerçekten çok beğendim. İlgilenen olabilir.

http://www.foxite.com/forum/read.aspx?id=0000137381

Visual Fox Pro
*!*    Author: Cetin Basoz

 
public oForm
oForm = createobject('MyForm')
oForm.show
 
define class myForm as form
  datasession = 2
  height = 300
  width = 450
  caption='Unpivot Sample'
 
  add object myGrid as grid with ;
    height = 300, width = 450, recordsource = 'crsFrequency'
 
  procedure load
    select t1.Country, City, cnt(*) as Frequency, t2.Frequency as freqCountry ;
      from (_samples+'data\customer') t1 ;
      INNER join ;
      (select Country, cnt(*) as Frequency ;
      from (_samples+'data\customer') group by 1) t2 ;
      on t1.Country == t2.Country ;
      group by 1,2,4 ;
      into cursor crsFrequency
  endproc
 
  procedure init
    with this.myGrid
      bindevent(.columns(1).Text1,'DblClick',this,'HandleDblClick')
      bindevent(.columns(2).Text1,'DblClick',this,'HandleDblClick')
      bindevent(.columns(3).Text1,'DblClick',this,'HandleDblClick')
      bindevent(.columns(4).Text1,'DblClick',this,'HandleDblClick')
    endwith
  endproc
 
  procedure HandleDblClick
    local lcTitle
    do case
      case inlist(upper(varread()),'COUNTRY','FREQCOUNTRY')
        select Country,City,Cust_id,Company,Contact ;
          from (_samples+'data\customer') ;
          where Country == crsFrequency.Country ;
          order by 1,2 ;
          into cursor crsUnPivot ;
          nofilter
        lcTitle = textmerge("Country:<<crsFrequency.Country>> Frequency:<<_Tally>>")
      case inlist(upper(varread()),'CITY','FREQUENCY')
        select Country,City,Cust_id,Company,Contact ;
          from (_samples+'data\customer') ;
          where Country == crsFrequency.Country and ;
          City == crsFrequency.City ;
          order by 1,2 ;
          into cursor crsUnPivot ;
          nofilter
        lcTitle = textmerge("Country:<<crsFrequency.Country>> "+;
          "City:<<crsFrequency.City>> Frequency:<<_Tally>>")
    endcase
    browse title m.lcTitle
  endproc
enddefine
Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü

2

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

1. varread() komutunu helpde bulamadım. ne yapıyor?
2. debug yapmak istediğimde kodun o noktasında "source not availible" dedi ?? halbuki açık kod...

VFP9 SP2

3

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

VarRead eski sürümlerde vardı. yeni sürümlerde controlsource vaya name property kullanılıyor bu komut yerine. geriye dönük uyumluluk için hala duruyor.

4 Son düzenleyen, cetinbasoz (17.12.2009 13:59:38)

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

1) varread() o anda uzerinde oldugunuz kolonun (browse, grid icin ya da herhangi bir kontrol) alan adini veriyor (grid.column.Controlsource gibi). VFP help, ne yazik ki, geriye uyumluluk sinifina sokuyor ve yerine Controlsource, Name property kullanin diyor. Oysa, bu VFP'nin geride biraksa da, yerini dolduramadigi birkac fonksiyondan birisi. Onun yerine simdi hicbir sey gecemiyor.

Customers tablosu gridde ise ve o sirada 2.kolondaysaniz, varread() 'Company' dondurur. Dogru bu controlsource'da var, ama oraya varread() gibi ulasmanin basit bir yolu yok (hittest ile kolonu bul, conrolsource'unu al uzun is).

2) Debug edebilmek icin, "kodu secip, sag klik, execute selection" yerine kodu bir prg dosyasina kaydet ve oradan calistir.

******************************************
Foxpro 2.6a help dosyasindan:

+---------------------------------+
¦            VARREAD()            ¦
+---------------------------------+
VARREAD()

-----------------------------------
Returns in uppercase the name of the memory variable, array element, or field used to create the current @ ... GET field or control.
Return value - Character
-----------------------------------

Controls include check boxes, fields, invisible, push or radio buttons, lists, popups, spinners, and text-editing regions.

If a Browse, Change or Edit window is active, the name of the current field is returned with the first letter of the field name capitalized.

VARREAD() is identical to SYS(18). Both can be used to pass the current field or control name to a procedure that in turn can provide context-sensitive help, as in the following example.

+---------------------------------+
¦             Example             ¦
+---------------------------------+
SET TALK OFF
CLOSE DATABASES
ON KEY LABEL F1 DO Help WITH VARREAD()
USE customer
SCATTER TO temp
DEFINE WINDOW input FROM 6,10 to 18,70 PANEL
ACTIVATE WINDOW input
@ 1,3  SAY 'Customer: ' GET company
@ 3,3  SAY 'Address: '  GET address
@ 5,3  SAY 'City: '     GET city
@ 7,3  SAY 'State: '    GET state
@ 7,18 SAY 'Zip: '      GET zip
@ 9,7  SAY 'Press <Esc> to cancel or <F1> for help'
READ
GATHER FROM temp
DEACTIVATE WINDOW input
RELEASE WINDOW input
ON KEY LABEL F1
RETURN

*** Help Procedure ***

PROCEDURE Help
PARAMETERS fieldname
DO CASE
    CASE fieldname = 'COMPANY'
        WAIT WINDOW 'Enter the company name' NOWAIT
    CASE fieldname = 'ADDRESS'
        WAIT WINDOW 'Enter the street address' NOWAIT
    CASE fieldname = 'CITY'
        WAIT WINDOW 'Enter the city name' NOWAIT
    CASE fieldname = 'STATE'
        WAIT WINDOW 'Enter a two-character state abbreviation' NOWAIT
    CASE fieldname = 'ZIP'
        WAIT WINDOW 'Enter the five-digit Zip code' NOWAIT
ENDCASE
RETURN

-----------------------------------

5

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

cetinbasoz yazdı:

...
Customers tablosu gridde ise ve o sirada 2.kolondaysaniz, varread() 'Company' dondurur. Dogru bu controlsource'da var, ama oraya varread() gibi ulasmanin basit bir yolu yok (hittest ile kolonu bul, conrolsource'unu al uzun is).
...

eğer gridde kolonların sırası değiştirilmişse varread()'ın yerini hiçbirşey tutamaz veya ben yolunu bulamadım.

Haksızlıklar karşısında susanlar, dilsiz şeytanlardır!
www.metinemre.com

6

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

Sen yolunu bulamamissin:) FoxyClasses olanlarda kodu var. Oradan yurutulen FindColumn ile biraz degisiklik yeter:

Visual Fox Pro
Procedure HandleDblClick

 
    Wait Window Nowait ;
        This.myGrid.Columns( ;
        this.FindColumn(This.myGrid,This.myGrid.ActiveColumn) ).ControlSource
 
    Local lcTitle
* ...
 
  Procedure findColumn(toGrid, nColIndex) && FoxyClasses'tan yurutme
    Local ix
    With toGrid as Grid
      For ix = 1 To .ColumnCount
        If .Columns(m.ix).ColumnOrder = m.nColIndex
          Return m.ix
        Endif
      Endfor
    Endwith
  Endproc
enddefine

7

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

teşekkürler... smile

Haksızlıklar karşısında susanlar, dilsiz şeytanlardır!
www.metinemre.com

8 Son düzenleyen, cetinbasoz (18.12.2009 14:27:30)

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

Yazarken hayiflandigim birsey eger kod VFP degil .Net olsaydi o findcolumn'a bile gerek olmayacakti (varread() yerine):

C#
((Column)this.myGrid.Columns

  .FirstOrDefault( ;
    c => c.ColumnOrder == this.myGrid.ActiveColumn ))
  .ControlSource

9

Re: Kodu gerçekten çok beğendim. İlgilenen olabilir.

LinQ ile bu kadarcık mı?

Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü