4D Code-Schnipsel

Wo geklickt in hierarchischer Listbox

Rausfinden, ob in einer Listbox eine Standardspalte oder Spalte der Hierarchie geklickt wurde. Doch das geht mein Rolf Darr und er hat recht
$P_LBobject:=OBJECT Get pointer(Object named;$lbObjName)
$standardColumn_b:=((($P_LBobject->)>0) & ($P_LBobject->{$P_LBobject->}=True))
$hierarchyColumn_b:=((($P_LBobject->)>0) & ($P_LBobject->{$P_LBobject->}=False))

Setting the dpi when exporting images

Suppose I want to export a SVG-picture container into a JPEG- or PNG-picture on disk. Doing nothing results into something resembling a 72 or 96 dpi picture, which is junk. These lines of code set the dpi in advance.

SET PICTURE METADATA($P_object->;TIFF xResolution;$dpi_L)
SET PICTURE METADATA($P_object->;TIFF yResolution;$dpi_L)
WRITE PICTURE FILE($path;$P_object->;$codec)

SFTP – Native to 4D?

Koen Van Hooreweghe on iNug

Hi Janet,

As others has mentioned, there is no native sftp client (yet?) in 4D. On Mac I’m using the OS built in sftp command which is called using LAUNCH EXTERNAL PROCESS.
For my purpose, I create a ‘batch’ file which contains the necessary sftp commands and then run it with sftp.

Eg. a possible content of the batch file could be:
cd /mydir
ls -1

Set the directory to mydir and get the directory listing. Keep in mind this is Unix, you must separate the lines with line feeds.

Then the command is like:
sftp -b ‘pathToBatchFileInPosixFormat’ -i ‘pathToIdentityFileInPosix’ -oPort=9999 username@serveraddress

pathToIdentityFileInPosix is the path to the rsa file containing your key. This file is normally stored in your home folder in a .ssh directory: /Users/yourname/.ssh
You can use eg System folder(Desktop) to get the path to your home folder. Just toss out the last part of the path.

The fun with this is you can setup and test first in terminal and when all is working as expected, move to 4D.


How to set Automatic Font?

Keisuke Miyako on iNug

some developer use
$autofont:=OBJECT Get font(*;““)
$autofont:=_o_Font name(0)
also works.

but to set at runtime, I think it is better to
OBJECT SET STYLE SHEET(*;““;Automatic style sheet)
OBJECT SET STYLE SHEET(*;““;Automatic style sheet_additional)
OBJECT SET STYLE SHEET(*;““;Automatic style sheet_main)

Where is this IP from?

Sometimes, I want to know while parsing the webserver-logfiles. There is a helpful service for that at freegeoip.net. This line of code
$status_L:=HTTP Request(HTTP GET method;“http://freegeoip.net/json/“+$IP;$contents_T;$responce_O)
is all I need. The $responce_O is self-explanatory. One caveat: up to 15.000 request per hour.
See also this MaPagenda-post.

Fritzbox aha API mit 4D

Peter Vogel hat sich die AVM Fritz!DECT 200 intelligente Steckdose geholt und dazu die nötige 4D Methode geschrieben, um Temperatur, Leistung, Energie etc. abholen zu können. Er stellt die Methode zur Verfügung und hat sie in die4Dwerkstatt veröffentlicht.

Hex-String to Number

do you want to „unhex“ the string?
$code:=“<!–4dtext 0x“+$hex+“–>“
PROCESS 4D TAGS($code;$code)
Keisuke MIYAKO 15 Juli 2015, 4Dforum

Python-Code ausführen

$program:=“/usr/bin/python -“
$py:=“import os\nprint os.environ[‚ARG1‘]“
CONVERT FROM TEXT($py;“utf-8″;$stdIn)
LAUNCH EXTERNAL PROCESS($program;$stdIn;$stdOut;$stdErr)
ALERT(Convert to text($stdOut;“utf-8″))
Keisuke MIYAKO 25 Oct 2016, 4Dforum

We need help to by pass GateKeeper

The process is basically goes like this:
– Install „Xcode“ from App Store. It’s large, so be prepared.
– Launch it.
– Goto Preferences / Accounts

weiter – Keisuke Miyako, 27 Nov 2016, 4Dforum

and there is some advice concerning default.4dd