AW: AW: Replace conditional statement with Polymorphism
Rudolf Bargholz
rudolf at bargholz.ch
Sat Jul 2 21:47:36 UTC 2022
Hi Martin,
There is a much simpler solution:
Do lList.$define(Col)
Do lList.$add('a')
Do lList.$add('aa')
Do lList.$add('www')
Do lList.$add('iiii')
Calculate lLen as 0
Do lList.$sendall(lLen.$assign(max(lLen,len($sendallref.Col))))
; FontOps.$wintextwidth(string,font-name|font-table-index,point-size[,font-style])
Do lList.$sendall(lLen.$assign(max(lLen,FontOps.$wintextwidth($sendallref.Col,'Arial',9))))
If you wanted, you could use the $reptextwidth() function in this calculation. You might have two texts with the same length but due to the different true type characters in the strings they have a different report pixel width.
Regards
Rudolf
Von: Martin Obongita <martin.obongita at yahoo.com>
Gesendet: Samstag, 2. Juli 2022 22:48
An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>; Rudolf Bargholz <rudolf at bargholz.ch>
Betreff: Re: AW: Replace conditional statement with Polymorphism
Hi Rudolf,
For max string length I am using:
For lLineNum from 1 to lCustomDataList.$linecount step 1
# Switch
#try switch case to get the len(1,2,3,4,5,6)
# End Switch
Calculate lString as lCustomDataList.1.2
Breakpoint
Calculate lColLength as len(lCustomDataList.[lLineNum].[lCol01])
If lColLength<lColLengthMax
Calculate lColLength as lColLengthMax
End If
Calculate lColLengthMax as lColLength
End For
Quit method lColLengthMax
Thank you ALL for your helps.
Martin.
On Saturday, July 2, 2022 at 11:15:11 PM GMT+3, Rudolf Bargholz <rudolf at bargholz.ch<mailto:rudolf at bargholz.ch>> wrote:
Hi Martin,
Why not just use the FontOps function $reptextwidth() to calculate the width of the longest value in the column, and then use that value to determine the width of your column. You will have to work out a max-width for the column, and if $reptextwidth() returns a value greater than this value, then use your max value, but this will reduce your code below to a very manageable and understandable block.
Regards
Rudolf Bargholz
-----Ursprüngliche Nachricht-----
Von: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com<mailto:omnisdev-en-bounces at lists.omnis-dev.com>> Im Auftrag von Martin Obongita via omnisdev-en
Gesendet: Samstag, 2. Juli 2022 19:50
An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>>; Rob Mostyn <mostyn at platformis.net<mailto:mostyn at platformis.net>>
Cc: Martin Obongita <martin.obongita at yahoo.com<mailto:martin.obongita at yahoo.com>>
Betreff: Re: Replace conditional statement with Polymorphism
Hi Rob,
I have a report class in which I want to display columns.
The length of the columns should depend on the longest data in that column.I get the data and approximate its length in pixels.
Calculate lColLength as pColLength
If lColLength<=5
Calculate lPixels as 1
Else If lColLength<=10
Calculate lPixels as 2
Else If lColLength<=15
Calculate lPixels as 3
Else If lColLength<=20
Calculate lPixels as 4
Else If lColLength<=25
Calculate lPixels as 5
Else If lColLength<=30
Calculate lPixels as 6
Else If lColLength<=35
Calculate lPixels as 7
Else If lColLength<=40
Calculate lPixels as 8
Else If lColLength<=45
Calculate lPixels as 9
Else If lColLength<=50
Calculate lPixels as 10
Else If lColLength<=55
Calculate lPixels as 11
Else If lColLength<=60
Calculate lPixels as 12
Else If lColLength<=65
Calculate lPixels as 13
Else If lColLength<=70
Calculate lPixels as 14
Else If lColLength<=75
Calculate lPixels as 15
Else If lColLength<=80
Calculate lPixels as 16
Else If lColLength<=85
Calculate lPixels as 17
Else If lColLength<=90
Calculate lPixels as 18
Else If lColLength<=95
Calculate lPixels as 19
Else If lColLength<=100
Calculate lPixels as 20
End If
Quit method lPixels
You are right that this is old Omnis classic mindset.If there is a way to replace the IF statement in my code, it will do me a great deal of good.
Rgds,Martin.
On Saturday, July 2, 2022 at 08:32:47 PM GMT+3, Rob Mostyn <mostyn at platformis.net<mailto:mostyn at platformis.net>> wrote:
H Martin,
object oriented programming requires a complete mind shift from procedural (Omnis Classic) programming. More than that, it is a multidimensional or rather multi layered mind shift. This transition took me about 18 months to get some 20 years ago. I am sure you are somewhere along the curve yourself but I/we cannot tell how far. My suggestion is that you focus on a class / subclass hierarchy to address, or at least partially address your challenge. The solution will most likely be a combination of the two methods.
Are your conditional statements implementing change in behaviour, change in business logic, change in presentation or change on … whatever? To answer your question properly requires a good understanding of your code base which you have and we don’t, so Its difficult to answer your questions succinctly.
Other may chip in with a more academic response.
Cheers,Rob
On 1 Jul 2022, at 20:45, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>> wrote:
Hi Listers,
I have an academic question about object-oriented programming.How is "polymorphism" implemented in Omnis Studio?
I have many conditional statements in my code: if...else if, switch...case that keeps breaking whenever I make a change in a related method elsewhere.Is there a sample library in the HUB which best described how to work with code that can take many forms?
Kind regards,Martin O.
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com <https://lists.omnis-dev.com%20> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com <https://lists.omnis-dev.com%20> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com<mailto:omnisdev-en at lists.omnis-dev.com>
More information about the omnisdev-en
mailing list