User Tools

Site Tools


en:documentation:script_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:documentation:script_example [2014/06/15 18:18] – [Use the ASCOM driver] pchen:documentation:script_example [2016/01/20 15:55] (current) – [Script example] pch
Line 2: Line 2:
  
 This page give tips and example of scripting functions.\\ This page give tips and example of scripting functions.\\
-You can also look at the three [[toolbox|standard tool box]] code from within the program.  +You can also look at the three [[toolbox|standard tool box]] code from within the program.\\  
 +For more details about a specific function see the [[script_reference|script reference]] page.
 ===== Generality ===== ===== Generality =====
  
Line 22: Line 22:
     a:=floattostr(ra);     a:=floattostr(ra);
     b:=floattostr(de);     b:=floattostr(de);
-    c:=Tstringlist.create;+    GetSL('STRL1',c); 
 +    c.clear;
     c.add('SLEW');     c.add('SLEW');
     c.add(a);     c.add(a);
     c.add(b);     c.add(b);
     r:=cmd('',c);     r:=cmd('',c);
-    c.free;+    c.clear;
     memo_1.lines.add(r);     memo_1.lines.add(r);
   end   end
   else memo_1.lines.add(rsTelescopeNot);   else memo_1.lines.add(rsTelescopeNot);
-  end.                                  +  end.
 </code>   </code>  
  
Line 90: Line 91:
  
 <code> <code>
-c:=Tstringlist.create;+GetSL('STRL1',c); 
 +c.clear;
 </code> </code>
-Create an instance of the TStringList object. Be careful that everything you explicitly create must be explicitly destroyed later to avoid a memory leak.+Request a TStringList object identified by STRL1We clear any data that may stay in the object.
  
 ---- ----
Line 109: Line 111:
 </code> </code>
 Execute the command and store the result in the variable r. Execute the command and store the result in the variable r.
- 
----- 
- 
-<code> 
-    c.free; 
-</code> 
-As soon we no more need the stringlist we destroy it to free the memory. 
  
 ---- ----
Line 256: Line 251:
 end. end.
 </code> </code>
 +
 +===== Open a document =====
 +
 +The following code open the Skychart documentation page in the default web browser.\\
 +You can use any document type with this function, the document open with the default application the same way as if you double click the document in the file explorer.
 +
 +<code>
 +begin
 +  OpenFile('doc\wiki_doc\en\documentation\start.html');
 +end.
 +</code>
 +
 +===== Run a command =====
 +
 +There is two different way to run an external command or program, depending if you want to wait for a result or not.
 +
 +==== Wait for a result ====
 +
 +The following command run the DIR command in the current directory. The result is stored in a stringlist and later show in a text memo. It contain the list of files in the directory.
 +
 +<code>
 +var r:TstringList;
 +begin
 +  GetSL('STRL1',r);
 +  r.clear;
 +  RunOutput('dir',r);
 +  Memo_1.lines.assign(r);
 +end.
 +</code>
 +
 +==== No wait ====
 +
 +If the command can run for an undetermined time or do not produce an output you need to use the following form.\\
 +This example run the Variable star observer program and exit immediately.
 +
 +<code>
 +begin
 +  Run('varobs');
 +end.
 +</code>
 +
  
en/documentation/script_example.1402849109.txt.gz · Last modified: 2015/11/06 20:34 (external edit)