### 4D Installation Guide
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Alphabetical-list-of-commands.902-976885.en.18.html
Guide for installing 4D.
```APIDOC
## 4D Installation Guide
### Description
This document provides instructions for installing 4D.
### Content
* 4D Installation Guide
```
--------------------------------
### Sequential Execution Example in 4D
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Methods.300-978012.en.html
Demonstrates sequential execution of 4D code, starting from the first line and proceeding to the last. Includes conditional logic and comments.
```4D
QUERY([People])
If(OK=1)
If(Records in selection([People])=0)
ADD RECORD([People])
End if
End if
```
--------------------------------
### Play Welcome Sound on Mac OS
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/JOUER-SON.301-977272.fr.html
This example shows how to play a specific sound resource named 'Bienvenue' upon application startup on Mac OS. This is typically placed in a startup method.
```4D
JOUER SON("Bienvenue")
```
--------------------------------
### Delete the last element of an array
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/DELETE-FROM-ARRAY.301-977324.en.html
This example demonstrates how to delete the last element of an array if the array is not empty. It first gets the size of the array and then calls DELETE FROM ARRAY with the size as the starting element index.
```4D
$vlElem:=Size of array(anArray)
If($vlElem>0)
DELETE FROM ARRAY(anArray;$vlElem)
End if
```
--------------------------------
### Open Resource File and List String Resources
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/RESOURCE-LIST.301-977576.en.html
This example demonstrates how to open the structure resource file and then list all string list resources. It handles platform differences for file paths and checks if the file was opened successfully before listing resources.
```4D
If(On Windows)
$vhStructureResFile:=Open resource file(Replace string(Structure file;".4DB";".RSR"))
Else
$vhStructureResFile:=Open resource file(Structure file)
End if
If(OK=1)
RESOURCE LIST("STR#";$alResID;$atResName;$vhStructureResFile)
End if
```
--------------------------------
### Get Coordinates of Objects Starting with 'button'
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/OBJECT-GET-COORDINATES.301-977894.en.html
This example demonstrates how to retrieve the coordinates of all form objects whose names begin with 'button' using the wildcard character '@'. Ensure the interpretation mode of the wildcard character is correctly set if needed.
```4D
OBJECT GET COORDINATES(*;"button@";LEFT;top;RIGHT;bottom)
```
--------------------------------
### Get Text Resource Example
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Resources.300-977556.en.html
This command retrieves text from a text resource. It is a shorter equivalent to using GET RESOURCE with BLOBs.
```4D
ALERT(Get text resource(20000))
```
--------------------------------
### Play Welcome Sound on Macintosh
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/PLAY.301-977272.en.html
This example shows how to play a sound file named 'Welcome Sound' on a Macintosh system. This code is typically placed in a startup method.
```4d
PLAY("Welcome Sound")
```
--------------------------------
### Assigning a Custom Starting Sequence Number
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Sequence-number.301-977675.en.html
If the sequence number needs to start at a number other than 1, add the difference to the result of Sequence number. This example shows how to start numbering at 1000.
```4D
[Table1]Seq Field :=Sequence number([Table1])+999
```
--------------------------------
### Build Applications with Project Files
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/BUILD-APPLICATION.301-977047.en.html
This example demonstrates how to use the BUILD APPLICATION command to build two applications by specifying their respective project XML files. It checks if the first build was successful before attempting the second.
```4d
BUILD APPLICATION("c:\\folder\\projects\\myproject1.xml")
If(OK=1)
("c:\\folder\\projects\\myproject2.xml")
End if
```
--------------------------------
### Install Event-Handling Method
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/ON-EVENT-CALL.301-978043.en.html
Installs a method to catch events. Pass the method name as a string. To stop catching events, pass an empty string.
```4D
ON EVENT CALL("MyEventHandlerMethod")
```
```4D
ON EVENT CALL("")
```
--------------------------------
### Custom Numbering with Offset
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Numerotation-automatique.301-977675.fr.html
Demonstrates how to start automatic numbering from a value other than 1. This example adds 999 to the next automatic number to make it start from 1000.
```4D
[Table1]NumAuto:=Numerotation automatique([Table1])+999
```
--------------------------------
### Example XML Structure
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/SAX-GET-XML-ENTITY.301-977085.en.html
This is an example of an XML document structure that includes a DOCTYPE declaration with an entity definition, which can be processed by the SAX GET XML ENTITY command.
```xml
]>
Entity updated by &name;
```
--------------------------------
### List Registered Clients on Startup
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/REGISTER-CLIENT.301-977770.en.html
This instruction can be placed in the On Startup Database Method to create a process that lists all registered 4D clients. It initializes a new process named '4D Client List'.
```4D
PrClientList:=New process("4D Client List";32000;"List of registered clients")
```
--------------------------------
### Get DTD Declaration using DOM Get XML document ref
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/DOM-Get-XML-document-ref.301-977087.en.html
This example demonstrates how to find the DTD declaration of an XML document. It uses DOM Parse XML source to create a document reference, then DOM Get XML document ref to get the document node, and finally DOM GET XML CHILD NODES to find the DOCTYPE node.
```4D
C_TEXT($rootRef)
$rootRef:=DOM Parse XML source("")
If(OK=1)
C_TEXT($documentRef)
// we are looking for the document node, since it is the node to which
// the DOCTYPE node is attached before the root node
$documentRef:=DOM Get XML document ref($rootRef)
ARRAY TEXT($typeArr;0)
ARRAY TEXT($valueArr;0)
// on this node we look for the DOCTYPE type node among the
// child nodes
DOM GET XML CHILD NODES($refDocument;$typeArr;$valueArr)
C_TEXT($text)
$text:=""
$pos:=Find in array($typeArr;XML DOCTYPE)
If($pos>-1)
// We retrieve the DTD declaration in $text
$text:=$text+"Doctype: "+$valueArr{$pos}+Char(Carriage return)
End if
DOM CLOSE XML($rootRef)
End if
```
--------------------------------
### Create Interprocess Array and Initialize Elements
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/ARRAY-REAL.301-977332.en.html
This example demonstrates creating an interprocess array of real elements and then iterating through it to set each element's value to its index. Ensure proper handling of interprocess variables.
```4D
ARRAY REAL(◊arValues;50)
For($vlElem;1;50)
◊arValues{$vlElem}:=$vlElem
End for
```
--------------------------------
### Get Cookie Header Content
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/GET-HTTP-HEADER.301-977179.en.html
Example of calling the GetHTTPField method to retrieve the 'Cookie' header content.
```4D
$cookie:=GetHTTPField("Cookie")
```
--------------------------------
### Example 1: Exporting Data in Binary Format
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/EXPORT-DATA.301-978046.en.html
This example demonstrates how to export data from all tables in a database in binary format using the EXPORT DATA command and a helper method.
```APIDOC
## Example 1: Exporting Data in Binary Format
### Description
This example illustrates the use of the EXPORT DATA command to export data in binary format. It loops through all database tables and calls the `ExportBinary` method for each.
### Method
APPLY
### Endpoint
/websites/library_4d-japan_doc_4dv12_4d_12_4
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```4d
C_TEXT($ExportPath)
C_LONGINT($i)
$ExportPath:=Select folder("Please select the export folder:")
If(Ok=1)
For($i;1;Get last table number)
If(Is table number valid($i))
ExportBinary(Table($i);$ExportPath+Table name($i);True)
End if
End for
End if
```
### Response
#### Success Response (200)
- **OK** (Longint) - Indicates if the export was successful (1 for success, 0 for failure)
#### Response Example
```json
{
"OK": 1
}
```
### Related Methods
#### ExportBinary Method
##### Description
This method handles the binary export of a specific table, configuring export settings using DOM XML.
##### Parameters
- **$1** (Pointer) - The table to export.
- **$2** (Text) - The path of the destination file.
- **$3** (Boolean) - Whether to export all records.
##### Code Example
```4d
C_POINTER($1) //table
C_TEXT($2) //path of destination file
C_BOOLEAN($3) //export all records
C_LONGINT($i)
C_TEXT($ref)
$ref:=DOM Create XML Ref("settings-import-export")
// Export the table "$1" in '4D' binary format, all the records or only the current selection
DOM SET XML ATTRIBUTE($ref;"table_no";Table($1);"format";"4D";"all_records";$3)
// Definition of fields to export
For($i;1;Get last field number($1))
If(Is field number valid($1;$i))
$elt:=DOM Create XML element($ref;"field";"table_no";Table($1);"field_no";$i)
End if
End for
EXPORT DATA($2;$ref)
If(Ok=0)
ALERT("Error during export of table "+Table name($1))
End if
DOM CLOSE XML($ref)
```
```
--------------------------------
### Connect to Oracle and Execute Queries
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/SQL-LOGIN.301-977494.en.html
Demonstrates connecting to an Oracle database using SQL LOGIN, executing a query on the Oracle database via SQL EXECUTE, and then executing a query on the local 4D database.
```4D
ARRAY TEXT(aNames;0)
ARRAY LONGINT(aAges;0)
SQL LOGIN("ODBC:MyORACLE";"Marc";"azerty")
If(OK=1)
`The following query will be redirected to the external ORACLE database
SQL EXECUTE("SELECT Name, Age FROM PERSONS";aNames;aAges)
`The following query will be sent to the local 4D database
Begin SQL
SELECT Name, Age
FROM PERSONS
INTO :aNames, :aAges;
End SQL
End if
```
--------------------------------
### Variable Initialization Example
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Error-messages.300-977009.en.html
Initializes a generic variable to False. This is a common starting point for boolean flags.
```4D
$0:=False
```
--------------------------------
### Extract Substring from String
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Substring.301-977469.en.html
Use Substring to get a portion of a string. If the number of characters is not specified, it returns characters from the start position to the end of the string. If the start position is out of bounds, an empty string is returned.
```4D
vsResult:=Substring("08/04/62";4;2)
vsResult gets "04"
```
```4D
vsResult:=Substring("Emergency";1;6)
vsResult gets "Emerge"
```
```4D
vsResult:=Substring(var;2)
vsResult gets all characters except
the first
```
--------------------------------
### Get XML Element Value
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/DOM-GET-XML-ELEMENT-VALUE.301-977116.en.html
This example demonstrates how to retrieve the value of an XML element using the DOM GET XML ELEMENT VALUE command. Ensure the element reference and value variable are correctly declared.
```4D
C_TEXT($xml_Element_Ref)
C_REAL($value)
DOM GET XML ELEMENT VALUE($xml_Element_Ref;$value)
```
--------------------------------
### Loading User Preferences with GET RESOURCE
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/SET-RESOURCE.301-977567.en.html
This code snippet shows how to load user preferences from a resource file using the GET RESOURCE command within the On Startup Database Method. It opens the resource file, retrieves the resource data into a BLOB, and then converts the BLOB back into variables. If loading fails, default values are assigned.
```4D
C_BOOLEAN(◊vbAutoRepeat)
C_LONGINT(◊vlCurTable)
$vbDone:=False
$vhResFile:=Open resource file("DB_Prefs")
If(OK=1)
GET RESOURCE("PREF";26500;$vxPrefData;$vhResFile)
If(OK=1)
$vlOffset:=0
BLOB TO VARIABLE($vxPrefData;◊vbAutoRepeat;$vlOffset)
BLOB TO VARIABLE($vxPrefData;◊vlCurTable;$vlOffset)
BLOB TO VARIABLE($vxPrefData;◊asDfltOption;$vlOffset)
$vbDone:=True
End if
CLOSE RESOURCE FILE($vhResFile)
End if
If(Not($vbDone))
◊vbAutoRepeat:=False
◊vlCurTable:=0
ARRAY STRING(127;◊asDfltOption;0)
End if
```
--------------------------------
### Change String Example 1
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Change-string.301-977482.en.html
Replaces characters starting from the second position. The result is assigned to the vtResult variable.
```4D
vtResult:=Change string("Acme";"CME";2)
```
--------------------------------
### Create Documentation - CREATE DOCUMENTATION Project Method
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/GET-DOCUMENT-PROPERTIES.301-977421.en.html
Creates or recreates documents on disk based on database records. It determines the save path, creates directories if they don't exist, and prepares to process records for document generation.
```4D
C_STRING(255;$vsPath;$vsDocPathName;$vsDocName)
C_LONGINT($vlDoc)
C_BOOLEAN($vbOnWindows;$vbDoIt;$vbLocked;$vbInvisible)
C_TIME($vhDocRef;$vhCreatedAt;$vhModifiedAt)
C_DATE($vdCreatedOn;$vdModifiedOn)
If(Application type=4D Client)
` If we are running 4D Client, save the documents
` locally on the Client machine where 4D Client is located
$vsPath:=Long name to path name(Application file)
Else
` Otherwise, save the documents where the data file is located
$vsPath:=Long name to path name(Data file)
End if
` Save the documents in a directory we arbitrarily name "Documentation"
$vsPath:=$vsPath+"Documentation"+Char(Directory symbol)
` If this directory does not exist, create it
If(Test path name($vsPath)#Is a directory)
CREATE FOLDER($vsPath)
End if
` Establish the list of the already existing documents
` because we'll have to delete the obsolete ones, in other words,
` the documents whose corresponding records have been deleted.
ARRAY STRING(255;$asDocument;0)
DOCUMENT LIST($vsPath;$asDocument)
` Select all the records from the [Documents] table
ALL RECORDS([Documents])
` For each record
$vlNbRecords:=Records in selection([Documents])
$vlNbDocs:=0
$vbOnWindows:=On Windows
For($vlDoc;1;$vlNbRecords)
` Assume we will have to (re)create the document on disk
$vbDoIt:=True
` Calculate the name and the path name of the document
$vsDocName:="DOC"+String([Documents]Number;"00000")
$vsDocPathName:=$vsPath+$vsDocName
` Does this document already exist?
```
--------------------------------
### Get Menu Item Key and Modifiers
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Get-menu-item-key.301-977941.en.html
This example demonstrates how to get the shortcut key code for a menu item and then check its associated modifier keys (Option, Shift). It's useful for handling different shortcut combinations.
```4D
If(Get menu item key(mymenu;1)#0)
$modifiers:=Get menu item modifiers(mymenu;1)
Case of
:($modifiers=Option key mask)
...
:($modifiers=Shift key mask)
...
:($modifiers=Option key mask+Shift key mask)
...
End case
End if
```
--------------------------------
### Open Quick Report Editor for Design/Printing
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/QR-REPORT.301-977714.en.html
This example opens the Quick Report editor, allowing the user to design, save, load, and print reports. Setting the document parameter to Char(1) forces the editor to display. The 'True' parameter enables the wizard.
```4D
QUERY([People])
If(OK=1)
QR REPORT([People];Char(1);False;True)
End if
```
--------------------------------
### Query and Launch Label Wizard
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/PRINT-LABEL.301-977794.en.html
This example enables user querying of the [People] table. If the query is successful (OK=1), it launches the Label Wizard, allowing the user to design, save, load, and print labels.
```4D
QUERY([People])
If(OK=1)
PRINT LABEL([People];Char(1))
End if
```
--------------------------------
### Get BLOB Size and Add Bytes
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/BLOB-size.301-977297.en.html
This example demonstrates how to get the current size of a BLOB variable and then add 100 bytes to it using the SET BLOB SIZE command. Ensure the 'myBlob' variable is a BLOB type.
```4d
SET BLOB SIZE(BLOB size(myBlob)+100)
```
--------------------------------
### List Directory Contents using External Process
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Get-4D-folder.301-977036.en.html
This example demonstrates how to list the contents of the database folder using the `LAUNCH EXTERNAL PROCESS` command. It's particularly useful on Mac OS where pathnames with spaces require quoting.
```4D
$posixpath:="\""+Get 4D folder(Database Folder Unix Syntax)+"\""
$myfolder:="ls -l "+$posixpath
$in:=""
$out:=""
$err:=""
LAUNCH EXTERNAL PROCESS($myfolder;$in;$out;$err)
```
--------------------------------
### GET HIGHLIGHT
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/GET-HIGHLIGHT.301-977276.en.html
Retrieves the start and end positions of the currently highlighted text within a specified object or field.
```APIDOC
## GET HIGHLIGHT
### Description
The GET HIGHLIGHT command is used to determine what text is currently highlighted in an object. It can be used with an object name (string) or a field/variable reference. The command returns the starting and ending positions of the highlighted text.
### Method
GET
### Endpoint
N/A (This is a 4D language command, not a REST API endpoint)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- ***** (Operator) - Optional - If specified, indicates that the `object` parameter is an object name (string). If omitted, `object` is a field or variable.
- **object** (Field, Variable, Form object) - Required - The name of the object (if `*` is specified) or the field or variable reference (if `*` is omitted).
- **startSel** (Longint) - Required - Output parameter that will store the starting position of the highlighted text.
- **endSel** (Longint) - Required - Output parameter that will store the ending position of the highlighted text (position of the last character plus one).
### Request Example
```4d
GET HIGHLIGHT([Products]Comments;vFirst;vLast)
If(vFirst
```
--------------------------------
### Get highlighted text Method
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/FILTER-KEYSTROKE.301-978155.en.html
This section details the 'Get highlighted text' method, explaining its parameters and return values. It also includes a code example demonstrating its usage in conjunction with dictionary lookups and text manipulation.
```APIDOC
## Get highlighted text Method
### Description
This method retrieves highlighted text from a given text string based on start and end positions. It handles cases where the start position is greater than or equal to the end position by searching backward for word boundaries.
### Method
Get highlighted text ( String ; Long ; Long ) -> String
Get highlighted text ( Text ; SelStart ; SelEnd ) -> highlighted text
### Parameters
#### Input Parameters
- **$0** (Text) - Output parameter for the highlighted text.
- **$1** (Text) - The source text string.
- **$2** (Long Integer) - The starting position of the selection.
- **$3** (Long Integer) - The ending position of the selection.
### Code Example
```4d
If($vtHighlightedText#"")
If($vlStart=$vlEnd)
$vlStart:=$vlStart-Length($vtHighlightedText)
End if
QUERY([Dictionary];[Dictionary]Entry=$vtHighlightedText+"@")
If(Records in selection([Dictionary])>0)
$2->:=Insert text($2->;$vlStart;$vlEnd;[Dictionary]Entry)
$1->:=$2->
$vlEnd:=$vlStart+Length([Dictionary]Entry)
HIGHLIGHT TEXT(vsComments;$vlEnd;$vlEnd)
Else
BEEP
End if
Else
BEEP
End if
```
### Response Example
(No specific response example provided for the method itself, but the code example shows how the output is used.)
```
--------------------------------
### Starting a Local Process in 4D
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/Identifiers.300-978006.en.html
Demonstrates starting a local process. Local process names are preceded by a '$' sign.
```4D
$vlProcessID:=New process("P_MOUSE_SNIFFER";16*1024;"$Follow Mouse Moves")
```
--------------------------------
### Get Highlighted Selection from Field
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/GET-HIGHLIGHT.301-977276.en.html
Retrieves the highlighted selection from a specified field. Use this to get the start and end positions of selected text within a field. The command returns significant selection positions only when applied to an area currently being edited.
```4D
GET HIGHLIGHT([Products]Comments;vFirst;vLast)
If(vFirst' operator is used to dereference the alias into a field pointer before passing it to the Field command.
```4d
FieldNum:=Field(->[Table3]Field2)
```
--------------------------------
### Make Resource Preloaded and Purgeable
Source: https://library.4d-japan.com/doc/4Dv12/4D/12.4/SET-RESOURCE-PROPERTIES.301-977562.en.html
This example sets a resource to be both preloaded and purgeable. Verify the resource ID and file variable are correct.
```4D
SET RESOURCE PROPERTIES('STR#';17000;Preloaded resource mask+Purgeable resource mask;$vhResFile)
```