Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Alpha 5 XBasic Classes and Objects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Alpha 5 XBasic Classes and Objects

    I have recently been introduced to the Alpha 5 system at a job that I just started. I have been assigned the task of writing an optimized set of common code for file management system that is duplicated in several places of their xBasic code.

    While I was working out a design for this, I ran across a button labeled "Include/Exclude Classes from List" under the "Open Script/Function" button in the code editor for filtering on class file. Coming from a background of writing in other languages that are or can be object oriented, such as Java, .NET, and PHP, I was very excited about the possibility of being able to re-write the code as a class.

    I have been scouring the wiki, references, and forums, in hope of finding examples of how it would be possible to create a user defined class. I have not had much luck.

    Does anyone have any input on this, such as whether or not user defined classes and objects are supported, or perhaps links to documentation on them? The only thing I have found so far relate to system classes and objects, which is not what I want. I have written a test class file, but have not had any luck in including it in my page or instantiating my class as an object. Any input or assistance would be welcome.

    #2
    Re: Alpha 5 XBasic Classes and Objects

    Just as a matter of making this more clear, here is what I have currently:

    A test class:

    Code:
    ' This class will be used for file manipulation,
    '	including saving the file to th file system and the sql database.
    define class global cnsFile
    
    	dim fileName as c
     	dim file as c
    
    	' Function saveFile
    	'
    	' This function saves the file passed in to the file system
    	' inserts a row to the database for that file.
    	'
    	' Passed: fileName
    	'
    	'
    	' Returned:
    	' 
    	function saveFile as v(fileName)
    		self.fileName = fileName;
    		return self.fileName
    	end function
    
    	' Function saveSQL
    	'
    	' This function saves the file passed in to the SQL database
    	' inserts a row to the database for that file.
    	'
    	' Passed:
    	'
    	'
    	' Returned:
    	' bol success - true or false based on save status 
    	function saveSQL as v()
    		'ui_msg_box("fileName",self.fileName)
    	end function
    end class
    A test page that uses the class:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta name="generator" content="Alpha Five HTML Editor Version 10 Build 4345-3709">
    <!-- must use in order to make XP Themes render -->
    <meta HTTP-EQUIV="MSThemeCompatible" content="Yes" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    
    <title></title>
    </head>
    <body>
    <p>
    <%a5
    	a5w_include("cnsFile.txt")
    	cnsFile.saveFile()
    %>
    </p>
    </body></html>
    After I publish this locally, this is the response I get in FireFox when I attempt to access the page:

    500 Internal Server Error
    "Script Error
    Error:Script: /testjb.a5w line:19
    cnsFile.saveFile()
    Not found
    cnsFile not found."

    Comment


      #3
      Re: Alpha 5 XBasic Classes and Objects

      You have several problems:
      1. Your class is not static and you are trying to use it without an instance.
      2. There is no return in Xbasic. You wouldn't want to return a value on a void function anyway.
      3. You are calling the saveFile() method with no arguments, but it requires a single argument to be passed.

      Lenny Forziati
      Vice President, Internet Products and Technical Services
      Alpha Software Corporation

      Comment


        #4
        Re: Alpha 5 XBasic Classes and Objects

        Also ui_msg_box(), which you are presumably using just for testing anyway, cannot be used in an A5W page. During development/testing, it is often easier to use a script in the development environment, where ui_msg_box() and debug() can be a tremendous help.

        Save the following as an Xbasic script to see it in action
        Code:
        'define class global cnsFile
        define class cnsFile
        
        	dim fileName as c
         	dim file as c
        
        	' Function saveFile
        	'
        	' This function saves the file passed in to the file system
        	' inserts a row to the database for that file.
        	'
        	' Passed: fileName
        	'
        	'
        	' Returned:
        	' 
        	function saveFile as v(fileName)
        		self.fileName = fileName;
        		'return self.fileName
        	end function
        
        	' Function saveSQL
        	'
        	' This function saves the file passed in to the SQL database
        	' inserts a row to the database for that file.
        	'
        	' Passed:
        	'
        	'
        	' Returned:
        	' bol success - true or false based on save status 
        	function saveSQL as v()
        		ui_msg_box("fileName",self.fileName)
        	end function
        end class
        
        
        dim cnsFileInstance as cnsFile
        cnsFileInstance.saveFile("ThisIsMyTestFile.txt")
        cnsFileInstance.saveSQL()

        Lenny Forziati
        Vice President, Internet Products and Technical Services
        Alpha Software Corporation

        Comment


          #5
          Re: Alpha 5 XBasic Classes and Objects

          Originally posted by Lenny Forziati View Post
          You have several problems:
          1. Your class is not static and you are trying to use it without an instance.
          2. There is no return in Xbasic. You wouldn't want to return a value on a void function anyway.
          3. You are calling the saveFile() method with no arguments, but it requires a single argument to be passed.
          How come you didnt give him the solution for #2?

          ANyways - I believe the return in xbasic is assigning your return value to your function.
          SO

          function saveFile as v(fileName)
          self.fileName = fileName;
          return self.fileName
          end function

          Becomes

          function saveFile as v(fileName)
          self.fileName = fileName;
          saveFile=self.fileName
          end function

          Your best bet is to return pointers

          Code:
          function saveFile as P(fileName [b]as C[/b])
                         dim ret as P
                         dim ret.error as L
                         dim ret.errorText as C
          		self.fileName = fileName;
          		if (code to save file)==.f. then
                                  ret.error=.t.
                                  ret.errorText="Could not save file"
                          end if
                          [b]saveFile=ret[/b]
          	end function

          Code:
                dim ret as P=obj.saveFile("c:/test.txt")
                if ret.error==.t. then
                      ?ret.errorText <<if this is on an a5w page - this line prints the error text to the page
                end if
          Scott Moniz - Computer Programmer/Analyst
          REA Inc.
          http://reainc.net
          (416)-533-3777
          [email protected]

          REA INC offers consulting services, programming services, systems design, database design, third party payment gateway integration (CHASE, PAYPAL, AUTHORIZE.NET) and developer support.
          If you need custom code, or 1-to-1 mentoring in any facet of your database/web application design,
          contact us to discuss options.

          Comment


            #6
            Re: Alpha 5 XBasic Classes and Objects

            Originally posted by aburningflame View Post
            How come you didnt give him the solution for #2?
            I knew someone else would be along to fill in that blank shortly



            Originally posted by aburningflame View Post
            ANyways - I believe the return in xbasic is assigning your return value to your function.
            Correct



            Originally posted by aburningflame View Post
            SO

            function saveFile as v(fileName)
            self.fileName = fileName;
            return self.fileName
            end function

            Becomes

            function saveFile as v(fileName)
            self.fileName = fileName;
            saveFile=self.fileName
            end function
            While this won't cause an error, it also won't return a value because the function definition sets the return type to v(oid). To get a value returned, it would need to be
            Code:
            function saveFile as [B]c[/B](fileName)
            		self.fileName = fileName;
            		saveFile=self.fileName
            end function



            Originally posted by aburningflame View Post
            Your best bet is to return pointers

            <sample code snipped>
            If you use the pattern of returning a pointer with detailed error information regulalry, you may be interested in using a CallResult. This is the same class used in Alpha's internal objects, and it takes care of resetting error codes and text for you when you set the Error or Success properties:
            Code:
            dim x as CallResult
            ?x
            = Canceled = .F.
            Code = 0
            Error = .F.
            NativeCode = 0
            NativeText = ""
            ReturnDataValue = <No data returned>
            Success = .T.
            Text = "Success"
            
            x.Error = .t.
            ?x
            = Canceled = .F.
            Code = -1
            Error = .T.
            NativeCode = 0
            NativeText = ""
            ReturnDataValue = <No data returned>
            Success = .F.
            Text = "Unknown error"
            
            x.Success = .t.
            ?x
            = Canceled = .F.
            Code = 0
            Error = .F.
            NativeCode = 0
            NativeText = ""
            ReturnDataValue = <No data returned>
            Success = .T.
            Text = "Success"

            Lenny Forziati
            Vice President, Internet Products and Technical Services
            Alpha Software Corporation

            Comment


              #7
              Re: Alpha 5 XBasic Classes and Objects

              We regularly return a pointer from our functions - however the callresult is too detailed for our needs.

              dim ret as P
              dim ret.error as L
              dim ret.errorText as C

              Is usually enough to suit our needs.

              Your other option is to create a custom class with all the options you would need to return - and return an object of that class. I havent used OOP techniques in Alpha - although I am very familiar with it in c#,php,java.

              Havent really seen the opportunity to use classes/objects - but - this should get you on your way.
              Scott Moniz - Computer Programmer/Analyst
              REA Inc.
              http://reainc.net
              (416)-533-3777
              [email protected]

              REA INC offers consulting services, programming services, systems design, database design, third party payment gateway integration (CHASE, PAYPAL, AUTHORIZE.NET) and developer support.
              If you need custom code, or 1-to-1 mentoring in any facet of your database/web application design,
              contact us to discuss options.

              Comment


                #8
                Re: Alpha 5 XBasic Classes and Objects

                Lenny Forziati and aburningflame:

                Thank you very much for all of the input that you have provided. I understand the xBasic class/object process much better now than I did. I hope this thread is as useful to anyone searching on the subject as it has been for me.

                Comment

                Working...
                X