FireFly and Visual Basic "dot" syntax - Interested?

Started by Paul Squires, August 29, 2013, 04:00:59 PM

Previous topic - Next topic

Paul Squires

A recent thread in the PB forums got me to thinking about implementing a "dot syntax" into FireFly. With the advent of the new PB object models, implementing a dot syntax is relatively easy. Below is a working code fragment and proof of concept of how such a system would work. As you can see, it is extremely close to the old Visual Basic syntax.

Such a model allows you do things like set or retrieve text of a control using object properties instead of FireFly Functions.
For example:

txtCustomer.Text = "Paul Squires"   ' set the text of the Customer TextBox
zText = txtCustomer.Text     ' retrieve the text of the Customer TextBox

Likewise, handling events would also be built into the classes.

I will play with this model to see if it is worthwhile to implement.

What do you guys think of the "Visual Basic" approach? Interested? Add it to FireFly as an additional/optional code generation framework?



#Compile Exe

%UNICODE = 1
%FALSE = 0
%TRUE = Not %FALSE

#Include "clsApplication.inc"
#Include "clsControl.inc"
#Include "clsForm.inc"   



Function PBMain() As Long

   Local MyApp       As iApplication
   Local frmMain     As iForm
   Local txtCustomer As iControl
   Local lblLabel    As iControl


   ' Create the Appliction (Project)
   MyApp = Class "clsApplication"
   
   
   ' Create a Form and add it to the Application
   frmMain = MyApp.Forms.Add( "Form", "frmMain" )

   
   ' Create a TextBox
   txtCustomer = frmMain.Controls.Add( "TextBox", "txtCustomer" )
   Prefix "txtCustomer."
      Left = 50
      Top  = 75
      Text = "Paul Squires"
   End Prefix
   
   ' Create a Label
   lblLabel = frmMain.Controls.Add( "Label", "lblLabel" )
   Prefix "lblLabel."
      Left = 100
      Top  = 125
      Text = "PlanetSquires"
   End Prefix


   ' Retrieve the control based on the control name and change
   ' properties associated with it.
   ' The Item method of the Controls collection allows us to
   ' use either the name or the numeric index in the collection.
   txtCustomer = frmMain.Controls.Item("txtCustomer")
   txtCustomer.Text = "Paul Squires - new"
   
   lblLabel = frmMain.Controls.Item("lblLabel")
   lblLabel.Text = "PlanetSquires - new"

   
   ' Display the newly changed text properties
   ? txtCustomer.Text & $CrLf & lblLabel.Text
   
   

   Local iFrm  As iForm
   Local iCtrl As iControl
   Local nFormIndex As Long
   Local nCtrlIndex As Long

   ' Iterate through all Forms in the project and all Controls
   ' on each Form. We use the numeric version of the Item method.
   For nFormIndex = 1 To MyApp.Forms.Count
     
      iFrm = MyApp.Forms.Item(nFormIndex)
     
      For nCtrlIndex = 1 To iFrm.Controls.Count
         iCtrl = frmMain.Controls.Item(nCtrlIndex)
         
         ? "Form:    " & iFrm.Name  & $CrLf & _
           "Control: " & iCtrl.Name & $CrLf & _
           "Type:    " & iCtrl.ObjectType & $CrLf & _
           "Text:    " & iCtrl.Text
      Next

   Next
   
   ? "complete"


End Function

Paul Squires
PlanetSquires Software

George Bleck

The odd thing is I "like" the function method made as it makes me feel like I wasn't using Visual Basic but something different and better  :D

All said and done though, I think the dot method makes stuff easier to understand, I can deal with functions if was left as that, but just don't use the PB method of writing stuff like "CONTROL GET TEXT hDlg, lID to strText".  Would like to brand the person that thought of that syntax format.

Eddy Van Esch

#2
I must admit that ever since objects and classes where introduced in the PB compilers, I still haven't started to use them ..  :-[   Not that I don't want to, but so far, everything I needed doing I could do in the 'classic' way. If I have the time, I will start learning about classes and objects ... Or is that just an excuse ..?  :o
That said, if FireFly would take care of some of the tedious and boring stuff for me, it would make the threshold to using classes a bit lower.
Just as long as the 'classic' way remains the same too.

So how do you picture this, Paul. Would the user have to set an option to have FF generate code the classic way or the object way? Many controls require sending messages to it to control them. Would this all be covered by the 'object' way?

Kind regards
Eddy

Paul Squires

Quote from: Eddy Van Esch on August 29, 2013, 07:42:42 PM
So how do you picture this, Paul. Would the user have to set an option to have FF generate code the classic way or the object way? Many controls require sending messages to it to control them. Would this all be covered by the 'object' way?
I would envision being able to use either syntax when you create a new project.

If using the new object syntax you would still be able to send traditional messages to the control. You would simply just have to retrieve the hWnd of the control from the control's object.

For example:
SendMessage txtTextBox.hWnd, %EM_SETSEL, 1, 10

The object way of doing it would be:
txtTextBox.SelStart = 1
txtTextBox.SelEnd = 10

FireFly would no longer track the hWnds of the controls and forms, but rather the objects. So, pressing F4 would bring up a list of objects (controls/forms). The biggest change would have to be in the code handlers. For example, notification event handlers would have a different syntax. I doubt that I would allow the traditional and new object event handlers to be intermixed within a project. That would be confusing for code generation. Therefore, the user would have to choose traditional or object when creating the project.

That's my initial thoughts.
Paul Squires
PlanetSquires Software

Carl Oligny


Jim Dunn

3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Eddy Van Esch

Quote from: TechSupport on August 29, 2013, 11:09:11 PM
Therefore, the user would have to choose traditional or object when creating the project.
I can live with that.
Eddy

David Warner

QuoteWhat do you guys think of the "Visual Basic" approach? Interested?
I like it.

QuoteAdd it to FireFly as an additional/optional code generation framework?
Optional is good, I'd also like the ability to choose traditional or object when creating a project.

Robert Eaton


Dennis Hoskins

Another thumbs up!  To be really useful it needs to be coupled with a strong intellisense function.
Dennis

Paul Squires

I was working with the code today and investigating how to integrate it into the whole framework of the existing FireFly environment. My thoughts are now is that we can have the best of both worlds in that the traditional and new style will be able co-exist within the same project. Hopefully my tests over the weekend will confirm this belief.  :)
Paul Squires
PlanetSquires Software

Martin Foster

This is something that I'd been hoping someone would implement for a very long time, so it's a BIG thumbs up from me  ;D

Martin

Marc van Cauwenberghe

That sounds great Paul. It is a sort of code completion that helps a lot. You be be able to extent it to FF_ functions as well.

Marc

Rolf Brandt

Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Thomas Cone Jr