An http server with 4D IC

4D_Tech Digest, Vol 94, Issue 52
Date: Sun, 22 Mar 2015 20:27:24 +0100
From: ?? ? Jorge

On 22/03/2015, at 16:30, Peter Jakobsson wrote:

I think what I'm looking for is the looping code that wraps the IC TCP commands to actually implement the listening function in multiple web processes and hand it off to a handler.

I'm less worried about actually parsing the request than receiving it in the first place. I am reminded of ITK's extensive shell consisting of 10's of methods and process interaction for wrapping the TCP listening activity.

Launch this in a New process:

While (True)
   $error:=TCP_Listen ($remoteHost;$localPort;8081;0;$socket)
   DELAY PROCESS(Current process;15)
   If ($error=0)
     $error:=TCP_Receive ($socket;$str)
     If ((Position("GET";$str)=1) & (Position("HTTP/1.1";$str)>0))
     //Build the $response here
     $response:="This is a test.\nThe query was: "+$str
     //And send it along with and after the headers
     $headers:="HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=UTF-8\r\n"
     $headers:=$headers+"Content-Length: "+String(Length($response))+"\r\n\r\n"
     $error:=TCP_Send ($socket;$headers+$response)
   End if
   $error:=TCP_Close ($socket)
   End if
End while

Try it with http://localhost:8081/

( Jorge )();


Unicode aus der Zwischenablage übernehmen

…for me the more annoying thing is NFD normalization in Unicode. I know copy-paste from PDF Unicode will result in NFD, whereas typing in a field produces NFC. I don't think Word is NFD, though, so I would consider paste from Word to be safe.

the problem with mixing NFD and NFC is that you can end up with the exact same length, one being longer than the other.

if you HIGHLIGHT TEXT such string, the position would be wrongly computed for every NFD sequence that could have been compressed using NFC.

now you may be wondering, what is NFD, NFC, and how should I care? that is actually my point, you really shouldn't have to care at all, most of the time.

if you want to be really defensive against NFD paste, then you could do
$text:=Get text from pasteboard
to quickly convert NFD to NFC.

miyako, 4D iNug Technical, Wed, 5 Nov 2014 17:13:46 +0100

How to sign a 4D app?

1. Goto Mac Dev Center
2. Sign in.
3. Click "Certificates, Identifiers & Profiles"
4. Click "Certificates"
5. Click Certificates/Production
6. Click and download "Worldwide Developer Relations Certificate Authority" and "Developer ID Certificate Authority".
7. Select Production/Developer ID and continue
8. Select Developer ID Application
9. Launch Keychain Access. (keep the browser open)
~Keychain Access~
10. select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority
11. In the User Email Address field, enter your email address
12. In the Common Name field, enter your name or company name.
13. The CA Email Address field should be left empty
14. Select the "Saved to disk" option
15. Continue
~back to the browser~
16. Continue
17. Upload the CSR file created with Keychain Access.
18. Download your certificate.

You should have installed 3 certificates,
Worldwide Developer Relations Certificate Authority,
Developer ID Certificate Authority,
and your own Developer Certificate,
in Keychain Access.
Now open terminal.
codesign -s "Developer ID Application: keisuke miyako" -f 
(obvious the name needs to be adapted)
drag and drop your built application 
Miyako, 8. Aug. 2014

Copy/Paste Email into 4D

Date: Thu, 24 Jul 2014 08:02:38 +0200
From: Keisuke Miyako

It really shouldn'€™t be this complicated, you know …

If (Form event=On After Edit)
  GET PASTEBOARD DATA("com.apple.flat-rtfd";$stdIn)
  LAUNCH EXTERNAL PROCESS("textutil -stdin -stdout -convert txt -format rtfd";$stdIn;$stdOut;$stdErr)
  Self->:=Convert to text($stdOut;"utf-8")
End if

Where does the 4DDebuglog get put by 4D Client?

SHOW ON DISK(GET 4D FOLDER(current logs folder))

Run that on the client; best way to answer this question (because the location can change for various reasons).
Josh Fletcher, Technical Account Manager, Thu, 10 Jul 2014 00:25:49

Popup Form Window

Auf einer eigenen Seite →

Reading lines from a text file

Subject: Re: Reading lines from a text file
Date: Tue, 11 Mar 2014 14:39:27 +0100
From: Vincent de Lachaux Vincent.deLachaux@4d.com

I have written code which does the job. It BLOBs the file, turns it into text, then checks each character. It's slow. I've written code which rolls a regex through the file, looking for lines - but I can't the regex which works here http://regexr.com/?38fv9 to work in 4D.

The correct pattern should be (with escaping for 4D) :
ARRAY LONGINT($rxPositions;0)
ARRAY LONGINT($rxLengths;0)
$rxMatch:=Match regex($rxPattern;$sourceText;1;$rxPositions;$rxLengths)

v i n c e n t d e L a c h a u x

The regex-pattern is working, but the code lacks. It should finally look like this:

ARRAY TEXT($P_array_T->;0)
While (Match regex($rxPattern;$sourceText;$i;$rxPositions;$rxLengths))
  If ($rxLengths{1}=0) // empty line
    $i:=$i+1 // check next occurence
    APPEND TO ARRAY($P_array_T->;Substring($sourceText;$rxPositions{1};$rxLengths{1}))
  End if
End while


Date: Sat, 1 Feb 2014 21:10:17 +0900
From: miyako <Keisuke.Miyako@4D.com>

another application of PROCESS 4D TAGS is to use (abuse?) it as an eval() in 4D. Example Hex to Int:
$html:="<!--4DTEXT 0x"+$hex+"-->"
PROCESS 4D TAGS($html;$value)


Sat, 1 Feb 2014 13:33:29 +1100
From: David Adams <dpadams@gmail.com>

I'm using some 4D tags and updating to the "new" (several years old by now) nomenclature. For those that haven't noticed, the tags are now:

4dhtml = "The value is already in HTML, don't HTML encode it." 4dtext = "The text is not HTML safe, please HTML encode it."

So, if you have a stored link and you want to embed it as an active link, use 4dhtml. On the other hand, if you want to display escaped as markup, use 4dtext.

4dtext = convert.

I was flipping these two around in my head and thought others might too.

For too long I've maintained a custom HTML encoder in my Text_ routine module. Yesterday I thought, "why am I doing that? 4D has an embedded HTML encoder?" So, here's a little method to exploit 4D's HTML encoder when you need it inside of code:

// Text_HTMLEncodeUsing4D
If (Text_ToHTMLEncode#"")
$command_text:="<!--#4dtext Text_ToHTMLEncode -->"
PROCESS 4D TAGS($command_text;$output_text)
End if

The theme here is Text, hence the prefixes of text for the variable and method. Rename to match your own style.

Note: There is absolutely no reason to call this method when you're using a 4D tag template directly. In that case, just call 4DTEXT from your template. This routine is for situations where you want to prepare HTML encoded data for some other purpose - like a POST to some REST API.

Now all I need is a really reliable URL encoder...

v13 WebArea Javascript question

Date: Sat, 11 Jan 2014 22:40:59 +0900
From: miyako <Keisuke.Miyako@4D.com>

The standard way pre-v14 to call 4D from WA is to use WA SET URL FILTERS

my favorite style is to

ARRAY TEXT($patterns;1)
ARRAY BOOLEAN($access;1)
WA SET URL FILTERS(*;OBJECT Get name(Object current);$patterns;$access)

and in JS have something like
function invokeObjectMethod(id,path) {
window.location = "webarea://" + id + "/" + path;

then calling 4D will be a matter of something like
assuming the path includes 3 key pieces of information.
i.e. the DOM id, the event name and data (optional) break up the path by

If (Match regex("webarea:\\/\\/([^/]+)\\/([^/]+)\\/?(.*)";$1;1;$pos;$len))
End if


…drag-and-drop from Apple's Mail program into 4D 13.4…

Wed, 11 Dec 2013 18:19:05 +1100
From: David Adams <dpadams@gmail.com>

Yes, I've gotten drag-and-drop from Apple's Mail program into 4D 13.4 working now. I'd tried this before and failed and after a user complained (nicely), I checked the list archives. I saw from past discussions that drops from mail include a proper file path during On Drag Over but return an empty path in On Drop. This is not how it works when you drag a file from the desktop. So, I've got the On Drag Over code stashing the last path in a process variable. In On Drop, I test the clipboard path and, if it's empty, try the variable. This seems to be working flawlessly and the user was super happy.

Thu, 12 Dec 2013 07:53:16 +1100
I thought that I'd try out dragging and dropping a message from Mail but there's no joy to be had there. On Drag Over and On Drop fire with no path. If you drag from Mail to the Desktop, you get a document ending in .eml, for those that are interested. Such a file can be dragged and dropped into 4D and you'll get a workable file path.

Listbox-dereference with 4D SQL

Date: Tue, 26 Nov 2013 05:43:07 +0100
From: miyako <Keisuke.Miyako@4D.com>

for that you can have a listbox with no variable name,
OBJECT GET pointer to get a pointer to that listbox based on its object name,
then use that pointer (notice there is no need to dereference the pointer in side SQL, 4D is smart enough to know a pointer always needs to be dereferenced
$LB:=OBJECT Get pointer (Object named; "LB")
Begin SQL

Is 4D Webserver running?

$url:="http://localhost:"+String(Get database parameter(Port ID))+"/4DWEBTEST"
$isWebRunning:= (200=HTTP Get($url;$response))
Keisuke.Miyako@4D.com in 4D_Tech Digest, Vol 77, Issue 66, 31 Oct 2013 21:31:25 +0900

Testen auf gültige eMail-Adress

Mit Regex auf eMail testen
$return_b:=Match regex($emailPattern;$givenEmailAddress;$start_L;$pos_found_L;$length_found_L)

Users und Groups loswerden

This code snippet will remove all users & groups except for Designer and Administrator:
SET BLOB SIZE($users;0)
I use this to keep the 4D user access system in sync with my custom system (which uses regular tables and fields).
Rob Laveaux

Funktioniert für Benutzer und Gruppen, die durch den Administrator angelegt wurden und man selber als Administrator eingeloggt ist.

Ein Bildschirm-Foto schießen

Nach einer Anregung durch Koen Van Hooreweghe, 28 Sep 2006, iNug

If (onWindows )
  sorry ("Kein Screenshot unter Windows")
  If (Count parameters=0)
  End if
    `capture the window
  If ($forClipBoard)
    $command:="screencapture -i -W -c"
    `delete the previous screendump
    $command:="rm -r"+$thepath
    $command:="screencapture -i -W -t jpg "+$thepath
  End if
End if

8. Mai 2013

ich habe bei Deinen Code Snippets gerade den screencapture Schnipsel gefunden.
Sehr nützlich.
Dein Schnipsel hat allerdings noch einen kleinen Schönheitsfehler:

   `delete the previous screendump
   $command:="rm -r"+$thepath

   $command:="screencapture -i -W "+$thepath

Das Bild hat so zwar die Endung .jpg, ist aber in Wirklichkeit ein PNG.
Wenn Du noch die Option "-t jpg" einbaust, stimmt der Inhalt mit dem Dateinamen überein.

Nur so zur Info.

Gruß aus Bremen,

Den Benutzer das Ziel eines PDF-Drucks auswählen lassen

Es wurde diese Frage in der NUG gestellt: I am looking to set the printer option for PDF, but want the user to select the destination. If you put "" in value2 it does not show a dialog on the Mac. Do I have to build my own save dialog?

Die Antwort von Miyako, 4D Japan: how about,
SET PRINT OPTION(Destination option ;3)
GET PRINT OPTION(Destination option ;$destination_l;$document_path_t)

Da hätte ich schon längst drauf kommen können :-)

Example of a TCP server + Client built with 4D IC

Below is a very simple 4D TCP server and client to see how one can start to learn how to use 4D IC low level TCP calls. … von Kevin LaTona

Diese Länder-Auswahl ist auch eine zweistufige hierarchische Liste, ist aber mit Records_2_HierList nicht erzeugbar. landauswahl Das ist eine flache Liste, die für jeden Buchstaben den ersten und den letzten Eintrag in die übergeordnete Liste einträgt. Auf diese Art wird die Länder-Liste auf 26 Einträge reduziert, das ist eine handhabbare Länge und nicht diese Monster, die mich auf vielen Webseiten stören.

Datensätze einer Tabelle in hierarchische Listen

Records_2_HierList setzt die hierarchische Struktur der Tabelle, dargestellt in zwei LongInt-Feldern, in einer hierarchische Liste um:
hlList:=Records_2_HierList (->[STÜCKLISTE];->[STÜCKLISTE]STL_LongInt;->[STÜCKLISTE]STL_Drüber_L;0;->[STÜCKLISTE]STL_Name)

  • $1 Pointer auf die Tabelle
  • $2 Datensatz-ID
  • $3 Knoten-Drüber Datensatz-ID
  • $4 Start-Knoten
  • $5 einzusetzender Text

Um Datensätze in hierarchischen Listen nutzen zu können, haben meine Datensätze alle eine eindeutige numerische ID (Longint). Die Longint berechnet sich aus (Sequenz number([Tabelle]) * 1000) + Table(->[Tabelle]). Sie werden gleich nachrechnen und feststellen, daß so maximal 2 Mio Datensätze in einer Tabelle eindeutig identifiziert werden können. Danach ist die Longint (232) zu kurz. Die V11 kennt die 264-Longint, leider die Oberflächen-Objekte noch nicht. Aber das wird sich im Laufe der Jahre auch noch ändern.


4D kann Methoden exportieren und wieder importieren. Wie ist in diesem PDF beschrieben.

Wenn Sie die Methoden als Text exportieren, müssen Feldnamen Buchstabe für Buchstabe in Quelle und Ziel übereinstimmen. Exportieren Sie als 4D-Methode ist die Methode tokenisiert und 4D setzt beim Öffnen die richtigen Namen ein.


Telefonhörer vor den Lautsprecher halten und 4D die Wähltöne erzeugen lassen. Dazu diese snd -Ressourcen verwenden! Manche Telefone sind funktional taub.

Generating Charts with the Google Chart API - Mac

Von "David Nasralla" download


ServerSideIncludes - SSI

Jahreszahl aktualisieren, z.B. � 2006 - 2017. Dazu verwende ich <!--#config timefmt="%Y" --><!--#echo var="DATE_LOCAL" --> Zuerst das Format auf nur Jahr anzeigen stellen, also %Y statt dem kompletten Format %d.%m.%Y, %H.%M und danach die Systemvariable DATE_LOCAL verwenden. Zwischen Formatangabe und Verwendung der Variablen kann beliebig viel stehen.