PlanetSquires Forums

Support Forums => General Board => Topic started by: raymw on November 18, 2019, 10:55:08 AM

Title: firefly to winfbe
Post by: raymw on November 18, 2019, 10:55:08 AM
For the past few days, I've been considering converting some of my firefly programs to winfbe. I've been solely concentrating on the graphics side of things, and changed my approach in doing this a few times in the process, weighing up the extra programming needed to automate the conversion, compared to manually re-designing the layouts in winfbe designer.

My current approach is to produce a list of controls from the firefly code, then in winfbe designer place the controls on a form, with no concern to position, etc., but just get the name of the control the same as in the firefly code.

After a fair bit of faffing about with Ascii/unicode, I have got the conversion to where I want it, for the moment. I'm unsure whether to push it further, to remove the need to manually create the rough winfbe layout.

In the image below, the left hand panel is the conversion program gui, the center panel is the original firefly layout, the right hand is the winfbe layout (it needs a few tweaks). The second image is the original winfbe layout, before the firefly alterations have been made, all that you have to do is shove on the controls and give them the right name. If you misname,  or leave out a control it is picked up in the conversion, giving the opportunity for corrections. Finally, you may need to edit colours, tab order and window styles, but most of the firefly programs I'm thinking of converting are nothing fancy, wrt the gui.

I may, or may not take this further, but generally by not converting the function coding automatically, it gives an opportunity for a rewrite and tidy up - well that's my excuse.

If anyone is interested in taking this further, or just playing around with the program, then I could most likely post the winfbe basic code here, but be aware it is pretty much a tangled mess- it was for my eyes only, has lots of go tos, dead ends, etc.
Title: Re: firefly to winfbe
Post by: SeaVipe on November 18, 2019, 12:11:12 PM
Thanks, Ray, that's a lot of work!
In my FF project, each form has an init routine where the majority of the controls are sized and positioned. Your idea of building a WinFBE form with the controls named the same as the FF originals works with some later tweaking.
Solving the mass of FF_ wrappers is another issue. As a starting point, I'm replacing them with the most appropriate of Josť's WinFBX functions.
Title: Re: firefly to winfbe
Post by: raymw on November 18, 2019, 02:22:26 PM
x1= Val(FF_TextBox_GetText( hwnd_grid_x1 )) would translate to x1=val(grid.x1.text) I believe. The button click events, I would use the stub code generated by the wnfbe designer, and copy in the ff fb code.  There is not that much to translate. I've not looked into it very much, but any ff_textbox_getText would translate to a null character, and inside the brackets, change the _'s to .'s , add .text and throw away the hwnd. Maybe it would only be a few rules to again do 90% of the ff code.

I found, when I moved over my little c# program to winfbe, a couple of weeks ago, that judicious application of search and replace is helpful (especially now Paul has fixed it).
None of my code is very fancy, I try to keep it simple for me, so other than time, or is it actually worth while, moving my firefly code over to winfbe should not be difficult. Arranging stuff in the designer, however is tedious to get it the way I want it, to match the firefly appearance.

I wonder, if we had enough examples of code in firefly and winfbe, if Google translate would sort it? or train our own neural net.  :)
Title: Re: firefly to winfbe
Post by: SeaVipe on November 18, 2019, 03:56:38 PM

Ray, as a quick fix to get things up and running:
Code: [Select]
#Include Once "C:\FireFly\CodeStore\FreeBASIC\FireFly_Functions\Control\FF_Control_SetText.bas"

Which expands to:
Code: [Select]
Sub FF_Control_SetText( ByVal hWndControl As HWND, _
                        ByRef TheText As String )
    ' Do a check to ensure that this is actually a window handle
    If IsWindow(hWndControl) Then 
       ' Set the control's text
       SetWindowText hWndControl, TheText
    End If
End Sub

This line works in an app:
Code: [Select]
' (text from a file) display it in a textbox.
FF_Control_SetText( frmMain.Text1.hWindow, "some text from a file..." )
So using your earlier idea of populating a WinFBE form with (say) textbox controls and then positioning and sizing according to the aforementioned FF code (which I modified manually), the new form looks pretty much like the original FF app.
BTW this does not preclude the use of the Visual Designer as I am adding a fair bit of new stuff to the forms in my converted app.
Title: Re: firefly to winfbe
Post by: Josť Roca on November 18, 2019, 04:49:15 PM
Why you don't simply use the API function SetWindowText instead of FF_Control_SetText?

No need for #Include Once "C:\FireFly\CodeStore\FreeBASIC\FireFly_Functions\Control\FF_Control_SetText.bas"
Title: Re: firefly to winfbe
Post by: SeaVipe on November 18, 2019, 05:34:47 PM
Right you are, Josť, I did eventually do just that but this was just a thought process on how one might get the same result with very little coding.
Title: Re: firefly to winfbe
Post by: Paul Squires on November 18, 2019, 06:37:30 PM
If you are converting from FireFly to WinFBE then make sure that you convert all of your string handling to use unicode. Therefore, use Jose's AfxSetWindowText. Also, use the CWSTR class in place of STRING.
Title: Re: firefly to winfbe
Post by: raymw on November 26, 2019, 07:17:54 PM
After a fair bit of messing about, I can load all my firefly forms (one by one, of course) into my conversion program, and it generates more or less the same appearance form in a winfbe basic file. Most of my firefly programs are not using controls that are not yet in winfbe, and if there is an odd one, then it shows it as the best match, or failing that as a text box. The form can be compiled and run, but at this stage it has no functionality. In my case, it is easy to add the code stubs for button clicks/whatever from the designer.

I then copy the firefly basic code into the winfbe code, moving the firefly functions for button clicks, whatever into the appropriate winfbe function stubs, and delete the fiirefly function headers.
Search and replace gets most of the remaining conversion done fairly quickly, leaving just a few odds and ends to be tidied up. For me, i don't think it is worth the effort trying to automate that any more.

So, the first thing  is to search and replace  'hwnd_form1_' with 'form1.'  or whatever your form is named

so that a ff statement such as x1= Val(FF_TextBox_GetText( hwnd_grid_x1 ))


x1= Val(FF_TextBox_GetText(grid.x1 ))

then search and replace 'FF_TextBox_GetText' with ''


x1= Val((grid.x1 ))   All the foregoing needs no special attention, do the whole program in one hit.

Use the compiler, and it will highlight the remaining errors, and many will be similar to adding '.text' after the x1 in the previous example

(depending on how precisely you have written the firefly code, you could search for '))' and replace with '.text))', but that could fail if you have other '))'

so very quickly lines such as x1= Val(FF_TextBox_GetText( hwnd_grid_x1 )) have become x1=Val((grid.x1.text))

similar for settext and many others.

Probably not much use if you've used ff controls such as scrollbars, images, or the like.

It took mre about 40 minutes to convert my last ff program to a 2400 line winfbe program, which may not mean much, but it would have taken me far longer than that to lay out the form in the designer, never mind writing the code..

Title: Re: FireFly to WinFBE Conversion
Post by: SeaVipe on November 26, 2019, 08:23:45 PM
Looks good, Ray.
As I mentioned earlier my forms use a central TAB control and a number of calendar controls (see image) so, for now, I will continue to convert to WinFBE manually. For some of the forms with textboxes and labels only I'll be sure to use your conversion method.
I like your use of hWnd as a Long in the FF_ wrappers (if I understood you correctly).
Jose noted earlier:
Why you don't simply use the API function SetWindowText instead of FF_Control_SetText?
No need for #Include Once "C:\FireFly\CodeStore\FreeBASIC\FireFly_Functions\Control\FF_Control_SetText.bas"

Search and replace would be easy enough.

Code: [Select]
SetWindowText frmMain.Text1.hWindow, "some text"
My database collection is made up of fixed length (main db), XML (SMS and Calls logs), ini (startup inits and debug logging) and csv (primarily for importing certain data files) and text/RichText files. Most of these will utilize SQLite in the WinFBE conversion (read NEW application). After a search for "easy to use" database formats I settled on SQLite. SQLite has the least painful learning curve, is well documented and the price is right. I'm sure that once I stop thinking of SQL as though it was a dBase III file I'll probably be able to start querying and get some results.

Title: Re: firefly to winfbe
Post by: Josť Roca on November 27, 2019, 12:16:47 AM
> I like your use of hWnd as a Long in the FF_ wrappers (if I understood you correctly).

Don't use hwnd as Long with FeeBasic or it will fail if compiled with the 64-bit compiler. Use as HWND instead. Handles are four bytes in 32-bit, but 8 bytes in 64-bit.
Title: Re: firefly to winfbe
Post by: raymw on December 05, 2019, 09:04:40 PM
The conversion I'm working on now, is a tad more complex than the previous two or three. In the original firefly code I used virtual lists, based on code by James Klutho, as I'm handling files of a few million lines of code, and am wanting to scroll around, modify values, etc. It worked very well, but looking at the firefly code, it has become a bit of a mystery as to the various variable names I used. I added bits of code over a period of a year or two. However, none-the-less, it has been simple to convert the graphical layout, and by selective search/replace, on the rest of the firefly code, the functionality is still there. I've not yet got around to replacing the  custom controls  with the winfbe listview, and I'm waiting for the tooltips to be implemented. I'm not sure if it is possible for the user to directly edit the values in the listview, but if so, I would have to also copy that change into the original list.
If you are of a sensitive nature, then do not open the jpeg....
Title: Re: firefly to winfbe
Post by: Paul Squires on December 06, 2019, 02:38:31 PM
Looks good Ray!  The ListView does not have editable cells (yet). I'll add that feature sometime down the road once I get all of the other major controls implemented. There is no reason that you still can't use the VList code in your WinFBE project. I am pretty sure (I think) that it was translated from PB code to FB code. You would simply make the call to create your controls in your Form's Load event handler. Of course, doing it manually means you would have the point/click drag/drop capabilities of the visual designer.
Title: Re: firefly to winfbe
Post by: raymw on December 06, 2019, 06:36:10 PM
I was looking at listview about a month ago. also parsing, and iirc I got the timing down reading in the file, parsing and showing it in listview, quicker than doing the same in firefly and showing it in the custom controls. I had roughed out the layout, and I think I'll merge the listview, which also parsed outa few more variables, into the editor program shown above. The vlist code was written in freebasic, but I implemented it with firefly, so much of it is commented out so far in my conversion to winfbe, there are a few firefly commands that I have not yet decided how to get into winfbe.
wrt editing the g-code files, I only edited a line at a time in the firefly version in the lh window- simply copied it out, changed it, and wrote it back, not editing in situ (more like edlin, not notepad) so I can do that with the listview version. I do not think I need the vlist code, the listview testing worked fine on the larger files.