Aauto User Library standard library usage guide

Source: Internet
Author: User
Tags thread

First create a dialog application, open Main.aau, and add a button to the dialog box, as shown below:

Then look at the button for a moment, click on the mouse pointer in the toolbox, and then click "Form" in the dialog designer, and the eight small squares around the button control are missing, which means he lost focus. And then we click on the right-hand "property panel" and modify the border properties to: resizable

With the border set to resizable, the form can be resized by dragging the mouse border after it is run.

Then continue to add a text box control on the dialog designer, drag the small square in the lower-right corner of the control to the appropriate size, as shown in the following figure:

Don't forget that the form is resizable, we want the control control to be the same size, always appear in the lower-right corner of the form, and then we want the text box control size to be variable, always as large as possible, first click on the text box control, and click "Fixed margin" in the property panel. The preceding plus sign expands all options:

Then set the properties of the left, right, top, and bottom four margins to True,true is true, False is false, in programming called "logical Value" or "Boolean value" and then Set "button control" to fix the bottom margin, fixed right margin by the above method. Then click "Run" in the quick hand to test the effect, try to maximize the dialog box to run the display. Then modify the Text property of the button control to "Point me Crawl", as shown in the following figure:

Then double-click the button control in the dialog designer to automatically switch to Code view. The Racer editor automatically adds an event function:

First, we remove the comment above, and the line with the start of the double slash is the comment statement, the general display is green, the annotation statement is ignored at run time, the comment statement here is just demo usage, we can delete unnecessary annotation first (do not include unnecessary annotation in the program is a good habit), become the following:

The function keyword defines a function that contains a small piece of code in a pair of curly braces, forming a short subroutine.

The next time we call this, we can just enter the function name with parentheses, for example, we execute the Code MainForm.button.oncommand () that executes the function we defined above.

But OnCommand is a special function that is not usually called by ourselves, but by the function called automatically by the form object when the user clicks the button-that is, the callback function.

For example, you know a new friend, he will say to you: Hi, please leave your phone number to me, you don't call me, I need to call you, this is a form of callback, the callback function is the same, you define mainForm.button.oncommand this function, The form will automatically call your OnCommand function when it is needed. We decided to change the contents of the text box when the user clicked the button, so we entered Mainform.edit. When you enter a dot, the Racer editor automatically lists all the available member properties, as well as member functions, for the control object named Edit. The following figure:

Experience is a good thing, all control usages are similar, even in different programming languages-commonly used property names, function names are similar, coupled with the quick editor to provide the code automatic prompts, we can generally quickly find the required attributes, or methods.

Some novice might say: "I am the real little white, no experience at all, I still want to know what properties are available for edit controls, preferably in Chinese." Well, I'll show you how to find these things, all window controls are defined in the Win.ui.ctrl namespace of the standard library ( Don't ask me what is the name space, you do not need to find out, in fact, I do not know. Locate Win.ui.ctrl.edit in the standard library and double-click the left mouse button to open the library file, as shown in the following figure:

Complete all our code as follows (mouse over code, and then you can see the Copy Source toolbar in the upper right corner of the code):

We further modify the above program, we want to click the button control is not just to show "Hello World", but to crawl a page of HTML source code, and displayed in the text box.

We want a namespace in the standard library called MyTools that contains the functions we need, and we want the MyTools namespace to have a mytools.gethtml () function to crawl the HTML source of the page.

Unfortunately, there is no such thing in the standard library, and of course we can add a custom library to the project's user base. Below we in the project with the right mouse button click "User Library", pop-up the following image menu:

Click "New Library" in the pop-up user library menu and pop up the new dialog box as shown below:

Directly enter the name of the new user library "MyTools", click on the "open" button, everything is smooth, in the "User Library" directory in the "project manager" more than the library file MyTools, and in the editor automatically opened the library, the following figure:

Default code added in user library

namespace defines a new namespace, we can add the required function in the namespace gethtml, modify the user library code as follows;

The return statement specifies the returned value of the function. Continue to modify the above code, will return "returned value"; Return to the source of the Web page instead.

Because we need to crawl the page, we need to use the Inet.http object in the standard library, we use the import inet.http; To import this library standby, modify the code as follows:

Click the "Save" button on the quick-speed toolbar to save the library file.

To switch to Main.aau, modify the button callback function for the following code:

We found a little shortage, mytools.gethtml () is only fixed to crawl the specified URL, which is very inconvenient, we go back to the MyTools user library, modify the URL to a variable function parameters, modified MyTools Library source code as follows (the modified part is bold word):

function more than a URL parameter, in the call required by the caller in the parameters of the URL to crawl, in the end of the MyTools user library, add a small section of smart hint configuration code, as follows:

Click the "Save" button to save the library file, and then right click on the user library in the project manager and click "Refresh directory, smart Tips" in the pop-up menu.

We go back to the Main.aau file and modify the MainForm.button.oncommand event callback function as follows:

We also encountered a problem, if the speed is slow, the crawl time will be very long, in a single threaded window program, if the thread is time-consuming operation blocked, also can not normal processing of user messages, resulting in user Click interface does not respond.

This is the time to use multithreading, the use of thread.create () can create a thread, we also use the Thread.waitone () function to wait for the thread to execute the completion.

In a window program, you can use the simpler Win.invoke () function to create a worker thread.

Win.invoke () Creates a worker thread execution code, waits for the thread to end, and then gets the return value.

We modify the Main.aau MainForm.button.oncommand function code as follows:

Read the above tutorial believe that there are some operational direction in mind.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.