Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic form design..
Message
From
29/05/2001 05:06:29
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
29/05/2001 03:51:50
Jimi Lee
Pop Electronic Products Ltd.
Hong Kong, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00510753
Message ID:
00512096
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
Hi Jimi,
:) Caught me on my being lazy :) You're right SourceObjects is useless there. Just think I eventually wrote that as a reply to you w/o a thorough thinking, testing etc. If you look closely there I also made a lot of unnecessary parameters passing too :) Instead of clearing, fixing them I kept them as is.
Normally a class like this should have a much more lightweight init (ie: just setting properties that passed to init) then do real processing in custom methods. Here is naother version (this time SourceObjects is used :)
Dimension arrObjects[20,2]
For ix=1 to alen(arrObjects,1)
  arrObjects[ix,1] = 'Label'+padl(ix,3,'0')
Endfor

oForm = createobject('myForm', @arrObjects, 400, 500)

Dimension arrObjects[120,2]
For ix=1 to alen(arrObjects,1)
  arrObjects[ix,1] = 'Label'+padl(ix,3,'0')
Endfor
oForm2 = createobject('myForm', @arrObjects, 300, 450)

With oForm
  .Caption = 'New objects would appear on this same form'
  .Show
  oForm2.Left = .Left + 100 && Cascade
  oForm2.Top = .Top + 100

  oForm2.Show && Show second also

  Messagebox('Will modify contents of first form...')

  Dimension .SourceObjects[120,2]
  For ix=1 to alen(.SourceObjects,1)
    .SourceObjects[ix,1] = 'Label'+padl(ix,3,'0')
  Endfor
  ._ClearForm
  ._BuildForm
  .Setall('Visible',.T.)
Endwith

Read events

Define class myForm as Form
  ObjWdth = 0
  ObjHgt = 0
  ColGap = 20
  RowGap = 5
  ColPerRow = 0
  RowPerPage = 0
  ObjPerPage = 0
  FrmHgt = 0
  PgfPageHeight = 0
  Dimension SourceObjects[1]

  Procedure Init
    Lparameters taObjects, tnHeight, tnWidth
    With this
      Acopy(taObjects, .SourceObjects)
      .Height = tnHeight
      .Width = tnWidth
      ._BuildForm()
      .Setall('Visible',.t.)
    Endwith
  Endproc

  Procedure _ClearForm
    Local lnMembers,ix
    lnMembers=amembers(arrMembers,this,2)
    For ix=1 to lnMembers
      This.RemoveObject(arrMembers[ix])
    Endfor
  Endproc

  Procedure _BuildForm
    Local oTempLbl, oTempTxt, oTempPgf, lnPages, ix
    With this
      oTempLbl = createobject('myLabel')
      oTempTxt = createobject('myTextBox')
      oTempPgf = createobject('myPageFrame',.Height,.Width,1)
      .ObjWdth = oTempLbl.Width + oTempTxt.Width + 5
      .ObjHgt  = oTempTxt.Height
      .PgfPageHeight = oTempPgf.PageHeight
      Release oTempLbl, oTempTxt, oTempPgf
      .ColPerRow = floor((.Width  - .ColGap) / .ObjWdth) && Max cols on a row
      .RowPerPage = floor((.Height - .RowGap) / .ObjHgt) && Max rows
      .ObjPerPage = .ColPerRow * .RowPerPage
      If alen(.SourceObjects,1) > .ObjPerPage && Need a pageframe
        .FrmHgt = .PgfPageHeight
        .RowPerPage = floor((.PgfPageHeight - .RowGap) / .ObjHgt) && Max rows
        .ObjPerPage = .ColPerRow * .RowPerPage
        lnPages = ceiling(alen(.SourceObjects,1)/.ObjPerPage)
        .AddObject('myPageFrame','myPageFrame',.Height,.Width,lnPages)
        For ix=1 to lnPages
          ._Addobjects(.myPageFrame.Pages(ix), ix)
        Endfor
      Else
        .FrmHgt = .Height
        ._Addobjects(this, 1)
      Endif
    Endwith
  Endproc

  Procedure _Addobjects
    Lparameters toTarget, tnGroup
    Local lnStart, lnStop, ix
    With this
      lnStart = (tnGroup - 1) * .ObjPerPage + 1
      lnStop  = min(tnGroup * .ObjPerPage, alen(.SourceObjects,1))
      For ix=lnStart to lnStop
        lnPosOnCol = (ix-lnStart) % .RowPerPage + 1
        lnPosOnRow = floor((ix-lnStart) / .RowPerPage)
        toTarget.AddObject('lbl'+padl(ix,4,'0'),'myLabel',.SourceObjects[ix,1])
        toTarget.AddObject('txt'+padl(ix,4,'0'),'myTextBox',.SourceObjects[ix,2])
        With eval('toTarget.lbl'+padl(ix,4,'0'))
          .Left = lnPosOnRow * (thisform.ObjWdth + thisform.ColGap)
          .Top  = (lnPosOnCol-1) * (thisform.RowGap + .Height)
          lnTxtLeft = .Left + .Width + 5
          lnTxtTop = .Top
        Endwith
        With eval('toTarget.txt'+padl(ix,4,'0'))
          .Left = lnTxtLeft
          .Top = lnTxtTop
        Endwith
      Endfor
    Endwith
  Endproc

  Procedure queryunload
    Clear events
  Endproc
Enddefine

Define class myPageFrame as PageFrame
  Procedure Init
    Lparameters tnHeight, tnWidth, tnPageCount
    With this
      .Height = tnHeight
      .Width = tnWidth
      .PageCount = tnPageCount
    Endwith
  Endproc
Enddefine

Define class myLabel as Label
  FontBold = .T.
  FontItalic = .T.
  BackStyle = 0
  Procedure init
    Lparameters tcCaption
    If !empty(tcCaption)
      This.Caption = tcCaption
    Endif
  Endproc
Enddefine

Define class myTextBox as Textbox
  Procedure init
    Lparameters tcControlSource
    If !empty(tcControlSource)
      This.ControlSource = tcControlSource
    Endif
  Endproc
Enddefine
Cetin


>Hi Cetin,
>
>Thanks again for this code, but I've some question about it.. (shame on my poor knowledge :( I'm especially poor at OOP...)
>
>What is the purpose of having the dimension SourceObjects[] in the MyForm class? I see you passed the lable name into it, but then you just use taObjects when defining the label objects.. so what did the SourceObjects[] do?
>
>Thanks a lot!
>
>Jimi
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform