Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make a builder?
Message
From
20/06/2006 09:57:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
20/06/2006 01:52:58
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01130150
Message ID:
01130235
Views:
25
This message has been marked as the solution to the initial question of the thread.
>Hi Everybody,
>
>I would like to request for any links or help on how to make a builder. I have not had any opportunity to even attempt to do one. My apologies if this happens to be a no-brainer question.
>
>Thanks in advance,
>
>Dennis

Dennis,
There are 2 type of builders basically - registered and nonregistered. Registered builders are explained under "How to: Specify a Builder Application with Builder.dbf" in help. I'll tell you about non-registered ones and some key aspects which you wouldn't see under the above topic. Nonregistered ones do not show up in rightclick menu but have some benefits over the registered ones (ie: you can manually pass multiple parameters as you wish).

A builder is just another prg or form (or even none - just select and execute). There are 3 function and methods which are available only in design time only and used by builders (additonally of course). First one is the most important.
1) When you invoke a builder it generally needs a reference to control(s) that are currently selected on a form, and/or to the form itself and/or to the dataenvironent of form. You get the reference with aSelObj(). aSelObj places selected controls' references into an array (or form, dataenvironment reference based on 2nd parameter).
2) WriteMethod(): You can write method code programmatically to desired controls' specified methods with this one.
3) CloneObject(): You can clone existing objects with this one.

Besides these 3 design time methods all functions/methods/commands are at your service in a builder.

Before building < g > the sample builder what is non-registered builder and how do you invoke it.
-It might be a prg or scx that's created and saved.
Select your controls on form, go to command window and call it. ie:
do myBuilder.prg
do myBuilder with parm1,parm2,...
myBuilder()
myBuilder(parm1,parm2,...)
do form myBuilder
do form myBuilder with parm1, parm2, ...
-It might not exist already and one that you think not to save at all (or create and run now + save). ie: You just quickly want to set all fontbold to .t. on a series of controls and just for fun wanted to do via a builder instead etc.
Select your controls on form, go to comand window, modify command [enter] to open a new code window.
Code there, select all, rightclick and execute
(you might directly do in command window too)

OK let's now create a simple non registered builder that would use all those 3 function/methods:
Scenario (normally this might not be the way to do this but we need something to sample all those 3 function/methods):
We want 12 checkboxes on the form with captions "January...December".
In their interactivechange they run a SQL to select orders where order_date is one of those checked.
We only create a checkbox on the form and set its visual style as we want. This one is serving both as a template and the left top one of the 12 checkboxes.

-Create a new form and put our checkbox on it. Set its visual aspects as you wish (or leave it to the builder code).
-Click on it to make sure it's the selected control
-Go to command window and open a new code window with "modi comm"
Write your commands (here is a sample to paste):
lnPerRow = 4 && 4 months on a row

lcMemberList = "January,February,March,April,"+;
  "May,June,July,August,"+;
  "September,October,November,December"
lcNamePrefix = "chkMonth"
lnMembers  = Occurs(',',m.lcMemberList)+1

TEXT TO m.lcCode TEXTMERGE noshow
Local lcInList,ix
lcInList = ''
For ix = 1 To 12
  if Evaluate('this.Parent.<<lcNamePrefix>>'+Ltrim(Str(m.ix))+'.Value')
      lcInlist = m.lcInlist + Iif(Empty(m.lcInlist),'',',') + Transform(m.ix)
   Endif
Endfor
lcInlist = '('+ m.lcInlist + ')'
Select * From (_samples+'data\orders') ;
  WHERE Month(order_date) In &lcInlist ;
  INTO Cursor crsOrders
ENDTEXT

Aselobj(aSelControl) && put all selected controls into an array
loObj = aSelControl[1] && ref to our checkbox

* Set base properties for our control
With loObj
  .FontBold = .T.
  .AutoSize = .T.
  .Name     = m.lcNamePrefix+Ltrim(Str(1))
  .Caption  = Getwordnum(m.lcMemberList,1,',')
  .BackStyle = 0
  .Value = .F.
  * this one would be in copies
  * as a result of cloning - if 1st run and cloned
  .WriteMethod("Click","wait window nowait 'Clicked '+this.Name")
  lnMaxWidth = .Width

  * Now create other copies of this object - CloneObject
  * Since this is a builder and not a wizard
  * we must check if control already exists
  * Builders unlike wizards are considered
  * to be runnable n times
  * Here we ignore the fact in case object already exists
  * it's not cloned - anyway not seeking for perfect code here:)
  For ix=2 To m.lnMembers
    If Type( '.Parent.' + m.lcNamePrefix+Ltrim(Str(m.ix)) ) != 'O'
      .CloneObject(m.lcNamePrefix+Ltrim(Str(m.ix))) && Clone it
    Endif
    * and modify some properties of the copy
    With Evaluate( '.Parent.' + m.lcNamePrefix+Ltrim(Str(m.ix)) )
      .Caption = Getwordnum(m.lcMemberList,m.ix,',')
      * will deal with left later but can deal with top now
      .Top = (Ceiling(m.ix/m.lnPerRow)-1) * (.Height + 5) + loObj.Top
      lnMaxWidth = Max(m.lnMaxWidth,.Width)
      .WriteMethod("InterActiveChange",m.lcCode) && Just copies have this
    Endwith
  Endfor
  * Now we know max wide - deal with left
  For ix=2 To m.lnMembers
    With Evaluate( '.Parent.' + m.lcNamePrefix+Ltrim(Str(m.ix)) )
      .Left = (m.ix-1)%m.lnPerRow * (m.lnMaxWidth + 5) + loObj.Left
    Endwith
  Endfor
Endwith
Select all, rightclick and execute selection.
Since this is a builder code you might select and execute N times but for the sake of sampling code is not perfect builder code (ie: on a second run if properties/methods of 1st object is changed new prop/method would not be in 'copies' as they are no more clones - might add a removeobject there).
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
Reply
Map
View

Click here to load this message in the networking platform