First of all, I am proud to say that www.sandstorm36.blogspot.com has reached half million page views (in case you haven't noticed on the right side below the countries). And that makes me feel happy knowing that my blabbing or some of those has indeed helped others and are not a waste of time for both yours and mine.
Moving on... I shared last time a way to show several objects within a grid's cell and I was surprised that it landed 2nd on my top posts. Said tutorial and sample uses 4 containers, if I can recall properly, and usage of DynamicCurrentControl. I did that when I was still in the process of experimenting on my assets masterfile module of which I use a grid with 3 columns with each columns showing different info:
And it works good and users of my app love it. However later it was mentioned to me by Cetin Basoz that it can be achieved via a single container object instead of 1 and 3 duplicates that shows different colors (as I have shown in Part II) via a DynamicFake method. So I checked and indeed it can be done so I changed into that approach. But then later I decided to overhaul again said module in favor of an html browser.
While I have the plan to create this post to show how to achieve the same using DynamicFake Method for a long time, it is repeatedly shelved as I am always busy doing a lot of other things..... until it was totally forgotten. But now and then, I come across someone in the forum asking the way to show several objects in a cell and so yesterday afternoon (Sunday), I decided to compose a sample for you guys to study. Here now is Part III - via Dynamic Fake Method. Please note that in both Part I, II & III (this now), we have to utilize a container object because without it placing several objects in a cell won't be possible.
What is Dynamic Fake Method?
In VFP, we are given several Dynamic Properties on grid for the purpose of showing Dynamic results based on conditions. When we say Dynamic, it means it is changing. And so if you wanted to show for instance different backcolors of cells based on conditions, then you will have to use DynamicBackColor. If you want to show different objects in a column like for one cell a textbox, the next cell an editbox, the 3rd a spinner... you can use DynamicCurrentControl. If you want to change bolding of fonts, use DynamicFontBold like this:
And that will show the Gender column on an alternating Bolded font and not. Some more Dynamic Properties are DynamicFontItalic, DynamicAlignment, etc (please look at your grid properties in PEM).
But aside from those fixed usage, I am not sure if this is by design or an unexpected feature of VFP's Dynamic Properties, we are allowed to use certain Dynamic Properties on something not totally meant for its name, i.e., via redirecting those to a form method instead and so the term DynamicFake Method. For instance, in this sample, I will be using DynamicFontBold but not to control bolding or not of a font but to manipulate all the objects inside the container inside the cell.
How Does DynamicFake Method works?
This works via passing a parameter of the objects you wanted to control later to the method you will create. The method does not need to be necessarily named Fake or similar but since the first developers who found this out and shows us as well coined the DynamicFake method name, then I will use the same as I agree we are faking those dynamic properties into believing they are doing what they are meant to do. But we control the naming of a method so you can give it any name you like such as ScoobyDoo if you wish.
Now in this sample, I use one container and 5 labels. You can use any objects you like and put those inside said container like a checkbox, spinner, editbox, textbox, etc. But this is just a demo and I am fine with labels so 5 labels. We can either pass all objects individually (in this case 5 labels) or just pass the container object. I prefer to do the latter.
From inside that method, I now control things like forecolor, fontbold, fontname, fontsize, etc. Again, we are not limited onto those. You can manipulate those objects based on its available properties. Sky is the limit per object's available properties, your choice.
DynamicFake Method implemented
Sample Codes
Epilogue:
Are we limited to the usage of DynamicFontBold for this faking need? Nope! All of the Dynamic properties can be faked with only one exception, i.e., DynamicAlignment. So for instance, instead of DynamicFontBold above, you can do this:
or
Actually if I will be faking again in the future, I will use a Dynamic that remained unused for Windows being those are designed for another OS such as:
So is VFP really powerful? You bet your a....err.... Without a shadow of a doubt!!!!
Cheers!
Moving on... I shared last time a way to show several objects within a grid's cell and I was surprised that it landed 2nd on my top posts. Said tutorial and sample uses 4 containers, if I can recall properly, and usage of DynamicCurrentControl. I did that when I was still in the process of experimenting on my assets masterfile module of which I use a grid with 3 columns with each columns showing different info:
And it works good and users of my app love it. However later it was mentioned to me by Cetin Basoz that it can be achieved via a single container object instead of 1 and 3 duplicates that shows different colors (as I have shown in Part II) via a DynamicFake method. So I checked and indeed it can be done so I changed into that approach. But then later I decided to overhaul again said module in favor of an html browser.
While I have the plan to create this post to show how to achieve the same using DynamicFake Method for a long time, it is repeatedly shelved as I am always busy doing a lot of other things..... until it was totally forgotten. But now and then, I come across someone in the forum asking the way to show several objects in a cell and so yesterday afternoon (Sunday), I decided to compose a sample for you guys to study. Here now is Part III - via Dynamic Fake Method. Please note that in both Part I, II & III (this now), we have to utilize a container object because without it placing several objects in a cell won't be possible.
What is Dynamic Fake Method?
In VFP, we are given several Dynamic Properties on grid for the purpose of showing Dynamic results based on conditions. When we say Dynamic, it means it is changing. And so if you wanted to show for instance different backcolors of cells based on conditions, then you will have to use DynamicBackColor. If you want to show different objects in a column like for one cell a textbox, the next cell an editbox, the 3rd a spinner... you can use DynamicCurrentControl. If you want to change bolding of fonts, use DynamicFontBold like this:
This.Column1.DynamicFontBold = "IIF(alltrim(gender)='Male',.T.,.F.)"
And that will show the Gender column on an alternating Bolded font and not. Some more Dynamic Properties are DynamicFontItalic, DynamicAlignment, etc (please look at your grid properties in PEM).
But aside from those fixed usage, I am not sure if this is by design or an unexpected feature of VFP's Dynamic Properties, we are allowed to use certain Dynamic Properties on something not totally meant for its name, i.e., via redirecting those to a form method instead and so the term DynamicFake Method. For instance, in this sample, I will be using DynamicFontBold but not to control bolding or not of a font but to manipulate all the objects inside the container inside the cell.
How Does DynamicFake Method works?
This works via passing a parameter of the objects you wanted to control later to the method you will create. The method does not need to be necessarily named Fake or similar but since the first developers who found this out and shows us as well coined the DynamicFake method name, then I will use the same as I agree we are faking those dynamic properties into believing they are doing what they are meant to do. But we control the naming of a method so you can give it any name you like such as ScoobyDoo if you wish.
Now in this sample, I use one container and 5 labels. You can use any objects you like and put those inside said container like a checkbox, spinner, editbox, textbox, etc. But this is just a demo and I am fine with labels so 5 labels. We can either pass all objects individually (in this case 5 labels) or just pass the container object. I prefer to do the latter.
From inside that method, I now control things like forecolor, fontbold, fontname, fontsize, etc. Again, we are not limited onto those. You can manipulate those objects based on its available properties. Sky is the limit per object's available properties, your choice.
DynamicFake Method implemented
Sample Codes
loTest = Createobject("Form1")
loTest.Show(1)
Define Class Form1 As Form
AutoCenter= .T.
Height = 400
Width = 600
Caption = 'DynamicFake Method Trick'
Add Object grid1 As Grid With ColumnCount= 1,;
Top = 0, Left = 0, HeaderHeight= 0, Width = Thisform.Width, Height = Thisform.Height,;
RowHeight= 65, RecordMark= .F.,DeleteMark= .F., ScrollBar = 2
Procedure Load
Select * From Home(2)+'Northwind\employees'Into Cursor junk NOFILTER
Endproc
Procedure Init
With This.grid1 As Grid
.RecordSourceType= 1
.RecordSource= 'junk'
.Column1.RemoveObject('Text1')
.Column1.AddObject('Container1','myContainer')
.Column1.Container1.Visible = .T.
.Column1.Sparse = .F.
.Column1.DynamicFontBold = 'thisform._DynamicFake(this.Column1.Container1)'
.Column1.Width = 590
Endwith
Endproc
Procedure _DynamicFake
LparametersoContainer
Local lcCountry, lcCity, lcEmployee, lcTitle
* Manipulate Country label
lcCountry = Alltrim(Country)
oContainer.lblCountry.ForeColor= Iif(m.lcCountry='UK',Rgb(0,128,255),Rgb(255,0,0))
oContainer.lblCountry.Caption= m.lcCountry
oContainer.lblCountry.FontSize= 14
*Manipulate City label
With oContainer.lblCityAs Label
lcCity = Alltrim(City)
.Caption = m.lcCity
Do Case
Case m.lcCity = 'Seattle'
.ForeColor= Rgb(128,128,255)
Case m.lcCity = 'Tacoma'
.ForeColor= Rgb(0,128,0)
Case m.lcCity = 'Kirkland'
.ForeColor= Rgb(255,128,0)
Case m.lcCity = 'Redmond'
.ForeColor= Rgb(0,128,255)
Case m.lcCity = 'London'
.ForeColor= Rgb(255,0,128)
Endcase
.FontItalic= .T.
Endwith
* Manipulate Employee label
With oContainer.lblEmployeeAs Label
lcEmployee = Alltrim(titleofCourtesy)+''+Alltrim(firstname)+''+Alltrim(lastname)
.Caption = m.lcEmployee
.FontBold=.T.
.ForeColor= Rgb(255,128,0)
.FontName= 'Calibri'
.FontSize= 20
Endwith
* Manipulate Title
With oContainer.lblTitleAs Label
lcTitle = Alltrim(Title)
.Caption = m.lcTitle
.FontName= 'Calibri'
.FontSize= 12
.ForeColor= Icase(m.lcTitle = 'Sales Representative',Rgb(128,0,0),;
m.lcTitle = 'Vice President, Sales',Rgb(128,128,255),;
m.lcTitle = 'Sales Manager',Rgb(128,128,128),Rgb(128,128,192))
Endwith
* Manipulate Date of Birth
With oContainer.lblDOBAs Label
.Caption = 'Date of Birth: '+Mdy(birthdate)
.FontName= 'Calibri'
Endwith
Endproc
Enddefine
Define Class myContainerAs Container
BorderStyle= 0
BackStyle= 0
Height = 65
Width = 590
BorderWidth= 0
Add Object lblEmployeeAsmyLabelWith Top = 0, Left = 0
Add Object lblTitleAsmyLabelWith Top = 30, Left = 0
Add Object lblCountryAsmyLabelWith Top = 0, Left = 500
Add Object lblCityAsmyLabelWith Top = 20, Left = 500
Add Object lblDOBAsmyLabelWith Top = 50, Left = 0
Enddefine
Define Class myLabelAs Label
BackStyle= 0
AutoSize= .T.
Enddefine
Are we limited to the usage of DynamicFontBold for this faking need? Nope! All of the Dynamic properties can be faked with only one exception, i.e., DynamicAlignment. So for instance, instead of DynamicFontBold above, you can do this:
.Column1.DynamicBackColor = 'thisform._DynamicFake(this.Column1.Container1)'
or
.Column1.DynamicCurrentControl = 'thisform._DynamicFake(this.Column1.Container1)'
.Column1.DynamicFontShadow = 'thisform._DynamicFake(this.Column1.Container1)'
So is VFP really powerful? You bet your a....err.... Without a shadow of a doubt!!!!
Cheers!