﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum / StrataFrame Application Framework / Business Objects and Data Access (How do I?)  / Field sizes / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>forum@strataframe.net</webMaster><lastBuildDate>Wed, 07 Jan 2009 17:08:16 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>I assumed that your code was going to be in a class... therefore Shared (in fact, when you put code in a module, .NET compiles the module as a class and then adds all of the methods to it as Shared :)).  As for the FieldLengths not being a property, you will need to change that line to:&lt;/P&gt;&lt;P&gt;box.MaxLength = CType(box.BusinessObject, BusinessLayer).FieldLengths(box.BindingField)</description><pubDate>Mon, 05 Mar 2007 09:00:11 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>Thanks Ben.  However, when I copy this code into my tools module, I get two errors:&lt;/P&gt;&lt;P&gt;1. Shared is not allowed in a module &amp;lt;--- I removed the Shared&lt;/P&gt;&lt;P&gt;2. box.BusinessObject.FieldLengths(box.BindingField) - FieldLengths is not a member of MicroFour.StrataFrame.Business.BusinessLayerBase &amp;lt;-- isn't FieldLengths a property of the IBusinessBindable interface?  If so, how do I cast that into your code example?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Ben</description><pubDate>Mon, 05 Mar 2007 07:27:15 GMT</pubDate><dc:creator>Ben Kim</dc:creator></item><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>No, reflection is going to slow you down tons... your best bet is probably to do a TryCast... it's much faster than catching any InvalidCastExceptions and a little faster than testing the TypeOf or GetType() of something.  And you'll also need to call it recursively (because not all of the textboxes are going to be in the root Controls collection).&lt;/P&gt;&lt;P&gt;Public Shared Sub SetAllMaxLengths(ByVal container As ContainerControl)&lt;BR&gt;    Dim box As MicroFour.StrataFrame.UI.Windows.Forms.TextBox&lt;BR&gt;    Dim container2 As ContainerControl&lt;BR&gt;&lt;BR&gt;    For Each ctrl As Control In container.Controls&lt;BR&gt;        box = TryCast(ctrl, MicroFour.StrataFrame.UI.Windows.Forms.TextBox)&lt;BR&gt;        If box IsNot Nothing Then &lt;BR&gt;            box.MaxLength = box.BusinessObject.FieldLengths(box.BindingField)&lt;BR&gt;        Else&lt;BR&gt;            container2 = TryCast(ctrl, ContainerControl)&lt;BR&gt;            If container2 IsNot Nothing Then&lt;BR&gt;                SetAllMaxLengths(container2)&lt;BR&gt;            End If&lt;BR&gt;        End If        &lt;BR&gt;    Next&lt;BR&gt;&lt;BR&gt;End Sub &lt;/P&gt;&lt;P&gt;You can then call this method from within any form by just passing Me as a reference to the parameter (because a form is a ContainerControl).</description><pubDate>Fri, 02 Mar 2007 16:59:41 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;I think I am close to a generic solution that I can call from any StrataFrame form.  However, I cannot for the life of me figure out what the proper AS "Control" to use from SF's object library.&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; SetMaxLengths(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; MyForm &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; MicroFour.StrataFrame.UI.Windows.Forms.BaseForm, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; BO &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; MicroFour.StrataFrame.Business.BusinessLayer)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt; For&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Each&lt;/FONT&gt;&lt;FONT size=2&gt; MyControl &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; Control &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;In&lt;/FONT&gt;&lt;FONT size=2&gt; MyForm.Controls 'HERE the AS CONTROL needs to be    &lt;BR&gt;    &lt;/FONT&gt;&lt;FONT size=2&gt;replaced with a more specific type of control from SF library since .BindingField &lt;BR&gt;    and .MaxLength are none standard&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;  If&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;TypeOf&lt;/FONT&gt;&lt;FONT size=2&gt; MyControl &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Is&lt;/FONT&gt;&lt;FONT size=2&gt; MicroFour.StrataFrame.UI.Windows.Forms.Textbox) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;BR&gt;    &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; MyControl.BindingField &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;BR&gt;            &lt;/FONT&gt;&lt;FONT size=2&gt;MyControl.MaxLength = BO.FieldLengths(MyControl.BindingField)&lt;BR&gt;    &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;    End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt; Next&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Or is there a better way with reflection?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;Ben&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Fri, 02 Mar 2007 13:35:41 GMT</pubDate><dc:creator>Ben Kim</dc:creator></item><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>Ben,&lt;/P&gt;&lt;P&gt;Thank you.  That worked like a charm.  Hopefully one of these days I will be as well versed in .NET as you :cool:&lt;/P&gt;&lt;P&gt;Now to make it generic so I can call it whenever initializing a form ;)&lt;/P&gt;&lt;P&gt;Ben</description><pubDate>Fri, 02 Mar 2007 12:53:35 GMT</pubDate><dc:creator>Ben Kim</dc:creator></item><item><title>RE: Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>We do not currently have plans to implement a "MaxSize" property on the business object... however, we already have a FieldLengths property... For string fields, it will contain the length of characters that the field can contain (i.e. for VarChar(150), the value will be 150).  For other data types, it will be 0 (and it's part of the partial class, so it gets updated when you rebuild the partial class).  As I said, though, we don't have plans to automatically set the MaximumLength property on a textbox to the specified value.</description><pubDate>Fri, 02 Mar 2007 08:57:36 GMT</pubDate><dc:creator>Ben Chase</dc:creator></item><item><title>Field sizes</title><link>http://forum.strataframe.net/Topic7248-6-1.aspx</link><description>This is more out of curiosity but also lends itself to efficiency.  When creating the BO's using the Business Object Mapper, shouldn't there be some way of creating a property with MaximumSize?  This way when creating the UI, I do not have to keep referring to our SQL Schema to find out the size of each field.  We have over 540 tables in our schema, more tables and fields being added by the DBA frequently so I cannot keep track of the sizes in my head.&lt;/P&gt;&lt;P&gt;So whether the field should accept 1 character or 5,000, it would be easier to type:&lt;/P&gt;&lt;P&gt;MyTextField.MaximumSize = Me.MyBO1.Field.MaximumSize - or if you look at my enhancement idea for an automatic screen builder wizard, this metadata could be used to set the property automagically.&lt;/P&gt;&lt;P&gt;You have the data in the DDT and even if you directly import into the BOM, all you need is an additional MaxSize field listed here to support this feature.  &lt;/P&gt;&lt;P&gt;So, out of curiosity, is this something that "might" be supported in the future?&lt;/P&gt;&lt;P&gt;Ben</description><pubDate>Thu, 01 Mar 2007 14:40:25 GMT</pubDate><dc:creator>Ben Kim</dc:creator></item></channel></rss>