Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic form design..
Message
From
24/05/2001 08:12:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
24/05/2001 05:53:52
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:
00510790
Views:
18
This message has been marked as a message which has helped to the initial question of the thread.
>Hi Cetin,
>
>This is even better than checking the screen resolution! I'm just not smart enough to think of this, heh.
>
>btw, are there any smarter ideas to create dynamic number of objects in runtime? I should be able to find it out from the MSDN but I'd like to learn how you experienced guys would do it.. would you mind teach me a bit? :p
>
>Thanks a lot! :)
>
>>
>>BTW Jimi,
>>You could also set form to maximize and check form height, width too. You could also use scrollbars (if VFP6) to use more objects.
>>Cetin

Might be:) Think of VFP5 and 3. They're not dead and can handle more than that could fit on screen using pageframes. If you look closely to form wizard it has code to add pageframe if all objects do not fit on a page and define initial layout in template forms.

Now consider you would only add label and textbox controls with fixed size (to keep it simple for this sampling).

Assume you have an array defining objects needed dimensioned [lnNumberOfObjects,2] with structure :
arrObjects[ix,1]=lcLabelCaption
arrObjects[ix,1]=lcTxtControlsource
this could be a table too :)
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)
oForm.Show
Read events

Dimension arrObjects[120,2]
For ix=1 to alen(arrObjects,1)
  arrObjects[ix,1] = 'Label'+padl(ix,3,'0')
Endfor
oForm = createobject('myForm', @arrObjects, 300, 450)
oForm.Show
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
  Local oTempLbl, oTempTxt, oTempPgf, lnPages, ix
  With this
    .Height =tnHeight
    .Width = tnWidth
    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
    Acopy(taObjects, .SourceObjects)
    .ColPerRow = floor((.Width  - .ColGap) / .ObjWdth) && Max cols on a row
    .RowPerPage = floor((.Height - .RowGap) / .ObjHgt) && Max rows
    .ObjPerPage = .ColPerRow * .RowPerPage
    If alen(taObjects,1) > .ObjPerPage && Need a pageframe
      .FrmHgt = .PgfPageHeight
      .RowPerPage = floor((.PgfPageHeight - .RowGap) / .ObjHgt) && Max rows
      .ObjPerPage = .ColPerRow * .RowPerPage
      lnPages = ceiling(alen(taObjects,1)/.ObjPerPage)
      .AddObject('myPageFrame','myPageFrame',.Height,.Width,lnPages)
      For ix=1 to lnPages
        ._Addobjects(.myPageFrame.Pages(ix), ix, ;
          .ObjPerPage, .RowPerPage, @taObjects, .ObjWdth , .ColGap, .RowGap)
      Endfor
    Else
      .FrmHgt = .Height
      ._Addobjects(this, 1, ;
        .ObjPerPage, .RowPerPage, @taObjects, .ObjWdth , .ColGap, .RowGap)
    Endif
    .Setall('Visible',.t.)
  Endwith
Endproc
  Procedure _Addobjects
  Lparameters toTarget, tnGroup, tnObjPerPage, tnRowPerPage, taObjects, tnObjWdth , tnColGap, tnRowGap
  Local lnStart, lnStop, ix
  With this
    lnStart = (tnGroup - 1) * tnObjPerPage + 1
    lnStop  = min(tnGroup * tnObjPerPage, alen(taObjects,1))
    For ix=lnStart to lnStop
      lnPosOnCol = (ix-lnStart) % tnRowPerPage + 1
      lnPosOnRow = floor((ix-lnStart) / tnRowPerPage)
      toTarget.AddObject('lbl'+padl(ix,4,'0'),'myLabel',taObjects[ix,1])
      toTarget.AddObject('txt'+padl(ix,4,'0'),'myTextBox',taObjects[ix,2])
      With eval('toTarget.lbl'+padl(ix,4,'0'))
        .Left = lnPosOnRow * (tnObjWdth + tnColGap)
        .Top  = (lnPosOnCol-1) * (tnRowGap + .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
Ç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
Next
Reply
Map
View

Click here to load this message in the networking platform