Is it possible to create a class/module or? the can contain overloaded methods to handle either desktop or webapp
Function doSomething(w as window)
Function doSomething(w as webpage)
by the same token… dealing with TextField vs WebTextField
I would like to be able to write ONE class where I can pass a “window” or “webpage”, loop thru all the controls
and perform various functions based on the control type and its attributes
Basically I want to create an add-on for gPDF where I can pass it a window/webpage at RUNTIME and create a PDF document that matches (as close as possible) to what the user is viewing at that moment.
my tests seem to show that desktop doesn’t know what web stuff is and vice-versa…
Alot of this could be handled with TARGET, except for the Function declaration itself?
For i As Integer = 0 To Self.ControlCount-1
processCTRL Self.ControlAtIndex(i).Name)
Next
Don’t is perfectly acceptable; not everything needs a drawn out explanation
Comic Sans? Don’t
Windows? Don’t
Purple text on a Keynote? Don’t
I would think that if you were able to mush the Desktop and Web code together you’d end up with a massive, slow module. I would think a user of your product might not appreciate that. Considering your users should be aware enough to know whether they need a Desktop or Web module, I don’t see the benefit of putting it all into one.
Dont is not only unacceptable. but is the incorrect answer… because it can be done… its not pretty, and requires using Variants which I dislike
Why would it be “slow” (not that lightning speed is a requirement for this)… Web would only compile the web code, etc… So while the source code might have extra stuff, the compiled version would not…
And this is the whole purpose of TARGET is to allow creation of one code base
here is my proof of concept
//
// Main Function - pass a window or webpage object
//
FUNCTION ProcessWindow(w as variant)
#If TargetWeb
Dim win As WebPage=w
Dim ctrl As WebObject
#ElseIf TargetDesktop
Dim win As Window
Dim ctrl As control
#Else
Return
#EndIf
//
Dim cnt As Integer=win.ControlCount
For i As Integer = 0 To win.ControlCount-1
#If TargetWeb
ctrl=win.ControlAtIndex(i)
If ctrl IsA WebTextField Then processTextField(ctrl)
#Else
If ctrl IsA TextField Then processTextField(ctrl)
#EndIf
ListBox1.AddRow(ctrl.Name)
Next
FUNCTION processTextField(ctrl as variant)
#If TargetWeb
Dim tf As WebTextField=WebTextField(ctrl)
#Else
Dim tf As TextField=TextField(ctrl)
#EndIf
//
// Not platform dependent from here down
//
Dim xpos As Integer =tf.Left
Dim ypos As Integer =tf.top
Dim width As Integer = tf.width
Dim height As Integer = tf.height
Dim txt As String=tf.Text
// do stuff with these values
END FUNCTION
the idea is NOT to have duplicate copies of 80% of the code in two places… gPDF itself is a single codebase and runs on EVERY Xojo platform except iOS (and maybe Rasp)
Mixing two frameworks is a bad idea. You are in fact complexifying your product for nothing IMHO.
Why corner yourself in an untenable place, both technically and commercially ?
What is so wrong about having gPDF Desktop, gPDF Web, and gPDF Console ? Lots of Xojo users will never ever do Xojo Web and will be content with a specific product. People who do Xojo Web are accustomed to have different products, and to pay for a specific support of Web.
because the difference is like 1% or less of the code… so to me its stupid (yes stupid) to have 3 different code bases that need to be maintained and tested, when the difference is a few dozen lines out of literally thousands…
The idea is ONE code base, ONE product. Anyone who licenses gPDF (encrypted or source) can use it on any/all platforms by simply making it an external item,
I see nothing untenable about it, either technically or commercially… as a matter of fact it makes it a whole lot easier
gPDF class has a total of 4 Target statements…
3 of them decide which UUID declares to use (OSX vs Win vs Linux)
1 skips a FontUnit statement for non-desktop compiles
Sure this add-on would be more Target heavy… but again I don’t see the complexity, since the Target protected code is to insure casting for the correct framework… and again 80% of the code will be non-Target specific
So had the answer been “You can’t” and I found that to have been true, I would have gone a differnet path, but it CAN, and it is not complex, it eases the burden on me as the Author, and imposes zero burden on the end user… Plug-n-Play
I did not write “You can’t”, I wrote “Don’t”. As in “if I were you, I would abstain”. I perfectly see how to do it. I simply think it is not a good idea.
Forgive me, but I feel you are putting your engineering mind before a sensible commercial approach.
There are reasons why most of the third party tools around are not one-size-fit-all.
Products that do it all have proven to be a downright bad commercial idea.
But hey, since you seem to know better. Good luck !
Yes you can and its directly supported IN THE IDE (no variants required)
Use the compat flags to your advantage
Set this function to be only compatible with desktop projects & turn all others off
FUNCTION ProcessWindow(w as Window)
Dim cnt As Integer=win.ControlCount
For i As Integer = 0 To win.ControlCount-1
If ctrl IsA TextField Then processTextField(ctrl)
ListBox1.AddRow(ctrl.Name)
Next
end function
Make this one Web ONLY by setting its compat flag
FUNCTION ProcessWindow(w as WebPage)
Dim win As WebPage=w
Dim ctrl As WebObject
Dim cnt As Integer=win.ControlCount
For i As Integer = 0 To win.ControlCount-1
ctrl=win.ControlAtIndex(i)
If ctrl IsA WebTextField Then processTextField(ctrl)
ListBox1.AddRow(ctrl.Name)
Next
Same for the process text field methods
Factor out the bits that are not common where you can and use compat flags
Anything that IS common can have its compat flags for all targets
This way you and your customer retain all the warnings & checks that the compiler can do so you compilation warnings not runtime failures (which would be the case using variants)
Sorry Michel, but you have not supported your “don’t” with any convincing arguments…
If I wanted to force people to buy multiple copies of gPDF if they supported multiple platforms, sure OK I could see that…
But on my end it would be a logisitcal nightmare…
If every other line of code was inserted or skipped via #IF target (ie, the targets exceeded say 10% of the code), then sure OK I could see that.
If this was a stand alone application (then the internals wouldn’t matter ) but selling multiple environment versions makes sense, but this is a toolset for Xojo developers who themselves are in multiple enviornments.
So I guess we can stop here, and agree to disagree…
It CAN be done, and the varying opinions on if it SHOULD be done have become irrelavant
To be honest… I had no idea… never paid attention to them, when I read you post it took me a second to figure what you were even talking about… So its an #IF TARGET but at a higher level (kind of)
[quote=295878:@Dave S]Sorry Michel, but you have not supported your “don’t” with any convincing arguments…
If I wanted to force people to buy multiple copies of gPDF if they supported multiple platforms, sure OK I could see that…
But on my end it would be a logisitcal nightmare…[/quote]
OK. My main argument is of commercial nature. It is IMHO clearer for the user, and maybe more profitable to have a product for each platform. But I am not paying your rent.
Not so sure a couple of classes for someone who has a lot of free time is a nightmare either…
[quote]Use the compat flags to your advantage
Set this function to be only compatible with desktop projects & turn all others off[/quote]
Like Dave… crikey, so THATS what they are there for.
Now Im wondering if this is finally a way to have an ActiveX control in a project , and still be able to build for Mac.
[quote=295893:@Jeff Tullin]Like Dave… crikey, so THATS what they are there for.
Now Im wondering if this is finally a way to have an ActiveX control in a project , and still be able to build for Mac.[/quote]
Unlikely since they are only a split between Desktop, Web, iOS and Console and dont go as far as Mac, Linux Windows etc
And they cant be applied to specific controls on a layout
What other purpose does a cross platform RAD tool have then to make it as easy as possible to share the same code?
You can do it safely and you can do it without performance implications. It just requires a lot of due diligence and testing across all project types and platforms to verify your assertions are correct.