📄 tips.en
字号:
[WELCOME]<p>Welcome to <b>Gambas</b> !<img src="img/gambas.png" align=right></p><p><b>Gambas</b> is a graphical developmentenvironment based on an advanced <i>Basic</i> interpreter.</p><p><b>Gambas</b> aims at enabling you to makepowerful programs easily and quickly. But clean programsremain on your <i>own</i> responsibility...</p><p>Enjoy it !</p><p align=right>Benoît Minisini<br><u>gambas@users.sourceforge.net</u></p>[STARTUP]<p>Each project must have a <i>startup class</i>. Thisstartup class must define a static public method named <i>Main</i>with no arguments, that will act as the startup method ofyour program.</p><p>You can define the startup class by clicking on it with theright mouse button in the project tree, and by selecting <i>Startup class</i> in the popup menu.</p><p>It is not necessary to define a <i>Main</i> method in a startupform, because it already has a predefined one.</p><p>This predefined startup method instanciates the form and shows it, like in<i>Visual Basic™</i>.</p>[OPEN]<p>The <b>OPEN</b> instruction of <b>Gambas</b> does notwork like the <i>Visual Basic</i> one. It does not return the fileas an integer, but as a <i>File</i> object.</p><p>So, instead of typing :</p><pre>DIM handle AS Integer...OPEN "myfile" FOR READ AS #handle</pre><p>you must type :</p><pre>DIM handle AS File...OPEN "myfile" FOR READ AS #handle</pre>[CATDIR]<p>Do you know that you can catenate directory names andfile names with the <b><tt>&/</tt></b> operator ? This operatordeals with the trailing slashes so that the resulting path isperfect.</p><p>For example:</p><pre>PRINT "/home/gambas" &/ ".bashrc"/home/gambas/.bashrcPRINT "/home/gambas/" &/ "/tmp" &/ "foo.bar"/home/gambas/tmp/foo.bar</pre><p>Isn't it marvellous ?</p>[EXEC]<p>You can make an executable file from your entire project. Select<i>Make executable</i> in the <i>Project</i> menu.</p><p>When <b>Gambas</b> makes an executable file, it puts the result in the directory of your project by default. The executable name has the same name as your project.</p>[PATH]<p>Relative paths have a special meaning in <b><i>Gambas</i></b>.They always refer to files inside your projects.<p>There is no concept of <i>current directory</i>, and no keyword like<tt>CHDIR</tt> to change it.<p><b>Be careful:</b> you must use relative paths only for accessingproject files, because absolute paths won't work anymore whenyou make an executable.[GLOBAL]There is <u>no global variables</u> in <b><i>Gambas</i></b>!<p>As a workaround, put them in your main module and declare themas <tt>PUBLIC</tt>.<p>If you do not have a main module in your project, but a mainform, then declare them as <tt>STATIC PUBLIC</tt>.<p>To access these variables, you must use the name of the main moduleor form: <tt>MyMainModule.MyGlobalVariable</tt> or<tt>MyMainForm.MyGlobalVariable</tt>.[EMPTY]<p>To know if a string is empty, it is not necessary to use the<b>Len()</b> function. You can directly test it, as an empty stringis <b>FALSE</b> and a non-empty string is <b>TRUE</b>.</p><p>For example, instead of doing :</p><pre>IF Len(MyString) > 0 THEN ...IF Len(MyString) = 0 THEN ...</pre><p>You should do :</p><pre>IF MyString THEN ...IF NOT MyString THEN ...</pre>[EVENT]<p>Every control, and every object that can raise events, has an<i>event observer</i> and an event <i>group name</i>.</p><p>The event observer catches every event raised by the object, andthe event group name is the prefix of the procedure called to managethe event.</p><p>By default, this event observer is the object where you havecreated the control, and the group name is the name of the control.</p><p>This way, a form receives all events raised by the controls youcreated inside.</p><pre>' Gambas formDIM hButton AS ButtonPUBLIC SUB _new() hButton = NEW Button(ME) AS "MyButton"ENDPUBLIC SUB MyButton_Click() PRINT "You have clicked MyButton !"END</pre>[FORM]<p>In <b><i>Gambas</i></b>, a form is its own event observer, so that you can directly manage its events (like <i>Resize</i>, <i>Activate</i>, ...) into its own class code.</p><p>This way, newbies coming from <i>Visual Basic</i> are notdisorientated :-).</p>[EMBED]<p>You can embed any form into other forms with <b><i>Gambas</i></b> !</p><p>To do such a powerful thing, just instanciate the form by passinga parent container as last argument of the contructor.</p><p>For example :</p><p><tt>DIM hForm AS MyDialog<br>DIM hSuperControl AS MyForm<br><br>' Create a dialog<br>hForm = NEW MyDialog<br>' Insert a form into this dialog<br>' Note that this form takes two parameters before the container<br>hSuperControl = NEW MyForm(Param1, Param2, MyDialog)<br>' Moves and resizes the form<br>hSuperControl.Move(8, 8, 128, 64)<br></tt></p><p>Be careful: a form embedded into another form is still a form, andso is its own event observer.</p>[GROUP]<p>Every control has a <i>(Group)</i> property. When this propertyis set, the prefix of the event handler name is the name of the groupand not the name of the control.</p><p>Let's suppose you have a <i>Button</i> named <b>btnAction</b>with the following <i>Click</i> event handler :</p><pre>PUBLIC SUB btnAction_Click()</pre><p>If you set the <i>(Group)</i> property of <b>btnAction</b> to<i>MyGroup</i>, then the event handler that will receive events fromthe button will be the following :</p><pre>PUBLIC SUB MyGroup_Click()</pre><p>This property lets you handle events of different controls ina single function. And the controls of the same group do not needto have the same type !</p><p><b>Note :</b> The old <i>Visual Basic</i> veteran may recognizethe concept of <i>control array</i>, but in a more powerfulimplementation. :-)</p>[TAG]<p>Each control has a <i>Tag</i> property. This property is for theprogrammer, and can contain any <b>VARIANT</b> data that you findrelevant.</p><p>This is very useful, when you want to distinguish controls of thesame group in a common event handler.</p>[LAST]<p>The <b>LAST</b> keyword returns the last control that hasreceived an event. This is very useful when you want to write anevent handler that is independent of any control name.</p><p>For example, let's suppose you want to write a calculator program.You have defined ten buttons, one for each digit, each one in thesame <i>group</i> "Digit". The <i>Tag</i> of each control is set tothe digit drawn in the button. Your event handler may look like that :</p><p><tt>PUBLIC SUB Digit_Click()<br><br> Display = Display & LAST.Tag<br> RefreshDisplay<br><br>END</tt></p>[LEFT]<p>The well known <i>BASIC</i> routines <b>Left$</b>, <b>Right$</b>and <b>Mid$</b> have useful behaviours in <b><i>Gambas</i></b></p><p>The second parameter of <b>Left$</b> and <b>Right$</b> isoptional, and is one by default.</p><p><tt>Left$("Gambas")</tt> returns <tt>"G"</tt><br><tt>Right$("Gambas")</tt> returns <tt>"s"</tt></p><p>This second parameter can be negative, and then gives the numberof characters not to extract.</p><p><tt>Left$("Gambas", -2)</tt> returns <tt>"Gamb"</tt><br><tt>Right$("Gambas", -2)</tt> returns <tt>"mbas"</tt></p><p>Likewise, the third argument of <b>Mid$</b> can be negative, andthen gives the number of characters from the end of the stringnot to extract.</p><p><tt>Mid$("Gambas", 2, -2)</tt> returns <tt>"amb"</tt>[END]<p>You have read all the tips of the days. I hope you have becamea <b>Gambas</b> expert now ! :-)</p><p>If you want to contribute, send new tips to the followingaddress :</p><p><u>gambas@users.sourceforge.net</u></p><p>Thanks beforehand !</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -