4D View ProはRリリース毎にさらに機能豊かになりつつあり、4D v17 R6も例外ではありません!新しいコマンドによって、4Dメソッドのパラメータ、名前、タイプとサマリーを特定することができます。そして、あなたのメソッドがより情報豊かで説明的になり、それらをエンドユーザーが使う助けになります。
日にちや時間を宣言したい場合は?そのメソッドが何をするのかをユーザーが理解するのを補助するために、短い説明を与えるのはいかがでしょう。VP SET ALLOWED METHODS コマンドで実行できるようになりました!
サンプルよりもこのコマンドを使う方法をより良く知る方法は何でしょう?あなたがサンプルの手順を読み終えて実行する頃までに、以下の結果が得られていることでしょう:
VP SET ALLOWED METHODSコマンドは、4Dメソッドを実行する新しい方法を提供します。以下のデモは4D View Proの式中にある”Birth Information” メソッドを呼び出したい場合にどのようにするかを示しています:
C_TEXT($1)
C_DATE($2)
C_TIME($3)
C_TEXT($0)
// Create a string from parameters
$0:=$1+" was born on "+String($2)+" at "+String($3)
オブジェクトを作成して、メソッドのコールネームを定義するためにオブジェクトの属性を使います:
$o:=New object
// Name of the method in 4D View Pro: "Birth Information"
$o.BIRTH_INFORMATION:=New object
次に$o.BIRTH_INFORMATION オブジェクトの中で、呼び出す4Dメソッドを定義します:
$o.BIRTH_INFORMATION.method:="Birth Information"
メソッドのパラメータについて情報を持ったコレクションを追加します:
$o.BIRTH_INFORMATION.parameters:=New collection
$o.BIRTH_INFORMATION.parameters.push(New object("name";"First name";"type";Is text))
$o.BIRTH_INFORMATION.parameters.push(New object("name";"Birthday";"type";Is date))
$o.BIRTHparameters.push(New object("name";"Time of birth";"type";Is time))
コマンドが何をするのかについてサマリーを特定します:
$o.BIRTH_INFORMATION.summary:="Returns a string from birth information"
最後に、4D View Pro式の中にある引数の数を、最小値と最大値を追加することで制限できます。例えば、パラメータの全てが必須の場合:
$o.BIRTH_INFORMATION.minParams:=3
$o.BIRTH_INFORMATION.maxParams:=3
メソッドが必要とする分だけ属性を作成することができます。それからメソッドオブジェクト($o)をVP SET ALLOWED METHODS コマンドに渡します:
VP SET ALLOWED METHODS ($o)
CHANGE CURRENT USER
のドキュメントには,下記のような記載がありました。
このコマンドを使用するためにはアクセス管理システムが有効化されている必要があります。言い換えると,Designer にパスワードが割り当てられている必要性があります。そうでない場合, CHANGE CURRENT USER には何の効力もなく,ユーザーを切り替えるための標準ウィンドウは表示されません。
v14以降,Designerのパスワードが設定されていない場合,CHANGE CURRENT USER
のパスワードチェックは省略されるようになりました。つまり,コマンドでカレントユーザーを切り替えるために,Designerのパスワードを設定する必要はありません。この点は,17r5以降のドキュメントに反映されています。
16r4以降,Undefined
は「参照」ではなく「値」を受け取るように改定されました。下記のようなコードをコンパイルモードで実行した場合,「ポインターの使用法が正しくないか,不明な変数へのポインターです」というエラーが返されます。
C_POINTER($W)
$W:=Get pointer("toto")
If (Undefined($W->))
ALERT("undefined")
End if
未定義のプロセス変数に対するポインターを検出したいのであれば,Undefined($W->))
ではなく,Type($W->)=Is undefined
のようなコードを記述することができます。
前のブログ投稿で、ORDA クエリーの中で式を適用して、洗練された複雑な検索条件をどのように構築するかを説明しました。さらに完全で強力な開発ツールを使って提供できるのが、新しいORDA メソッドのorderByFomula() です。formulas の助けによって、プロジェクト・メソッドあるいは4D式の中で複雑な条件を使ってエンティティ・セレクションのソートができます。
ソート条件は、式がストリングあるいは Formula オブジェクトとしてorderByFormula() メソッドに与えられた時に評価されます。
ここにデータクラス、Companiesがあります。これからこの企業を収益(収益 = 収入 - 支出)を基にソートします。
エンティティはThis コマンドでアクセスすることに注意しましょう。
C_OBJECT($companies;$orderedCompanies;$formula)
$formula:= Formula(This.revenue - This.costs)
$companies:=ds.Companies.all()
$orderedCompanies:=$companies.orderByFormula ($formula;dk descending)
では同じ条件を使って企業をソートしますが、ストリングの代わりに、Formula オブジェクトを使い、降順でソートします。
C_OBJECT($companies;$orderedCompanies;$formula)
$formula:= Formula(This.revenue - This.costs)
$companies:=ds.Companies.all()
$orderedCompanies:=$companies.orderByFormula ($formula;dk descending)
Formula オブジェクトを使うことで、式をストリングとして使うよりもいくつかの利点(自動補完、コードエディター内の色指定、など)があります。
orderByFomula() メソッドはさらに多くのオプションがあります。詳しくはドキュメントをチェックし、上記のサンプルデータベース (HDI)をダウンロードしてください。
query() メンバーメソッド自体の内部にorder by ステートメントを挿入することができます。これはクラアント/サーバー・モードで使う場合には大きな利点で、クエリーとソートアクションを同じリクエスト中に組み合わせることができ、サーバーとネットワークトラフィックに送られるリクエストの数を減らします。
C_OBJECT($companies)
$companies:=ds.Companies.query("revenue> :1 order by costs desc";5000)
クイックレポートは64ビットで完全に再作成され、継続的に新しい機能が統合されています。前回のRリリースのUI(ユーザーインターフェイス)の改良に加えて、4D v17 R6はスタンドアロンレポート中のイベントを捉える機能と、小計スペースを管理する機能を追加しました。
QR REPORT コマンドに”methodName”パラメータを設定できるようになりました。このメソッドは管理されたイベントごとに起動するコールバックです:
以下はコールのサンプルです:
QR REPORT([My Table];Char(1);"qrCallbackMethod")
コールバックメソッドでは、管理されたイベントすべてを途中でやめて、やるべきことをやり、QR EXECUTE REPORT コマンドでイベントを実行できます。
下記はコールバックメソッドのサンプルで、文書を生成する前にフッターに現在のタイムスタンプを設定し、プレビューイベントにフィルターをかけます:
C_LONGINT($1;$2)
C_LONGINT($zone;$event)
$zone:=$1
$event:=$2
Case of
: ($event=qr cmd generate)
QR SET HEADER AND FOOTER($zone;2;"";Timestamp;"";100)
QR EXECUTE COMMAND($zone;$event)
: ($event=qr cmd print preview)
Else
QR EXECUTE COMMAND($zone;$event)
End case
それぞれのブレイク(小計)に対して、ページブレークあるいは異なる行高を設定できるようになりました。異なる行高の場合、違いはポイント(pt)とパーセンテージ(%)で表示できます。
既存のコマンドが改良され,さらに便利になりました。フォームオブジェクトのカラーは,数値だけでなく,直感的なCSS文字列でも指定することができます。従来のような4バイトの倍長整数(0x00RRGGBB)では,すぐに色がイメージできなかったかもしれません。255(0xFF)とではなく,単純に”blue”と記述できれば良いのに,と感じていたデベロッパーには朗報です。17r6では,CSS文字列がサポートされるようになりました!
CSS文字列がサポートされるようになったコマンドは,OBJECT SET RGB COLORS, LISTBOX SET ROW COLOR, LISTBOX SET GRID COLOR です。
コマンドの改良により,下記の要領でオブジェクトの色指定ができるようになりました。
$color:="blue"
$color:="#0000FF" // または #FF
$color:="RGB(0,0,255)"
OBJECT SET RGB COLORS コマンドには,前景色と背景色がそれぞれ文字列で渡せるようになりました。コードを記述するのが簡単になるだけでなく,可読性も向上します。
OBJECT SET RGB COLORS(*;"text";"red";"Yellow")
// 従来の表記 OBJECT SET RGB COLORS(*;"text";0xFF0000;0xFFFF00)
それだけではありません。OBJECT GET RGB COLORS コマンドからも文字列でCSSカラーが返されるようになりました。
C_TEXT($front;$back)
OBJECT GET RGB COLORS(*;"rectangle";$front;$back)
ALERT($front+"/"+$back) // #0000FF/#90EE90 が返される
リストボックスのコマンドも同じように改良されていますが,注意点があります。LISTBOX SET ROW COLOR にCSS文字列が渡された場合,リストボックスや列のカラーを制御するための配列には,数値に変換された値が代入されることに留意してください。
サポートされているCSSカラーネームの一覧はドキュメントに掲載されています。
早速,HDIをダウンロードして,改良コマンドを試してみるのはいかがでしょうか。
SQLでログインする場合,On SQL Authentication
データベースメソッドでCHANGE CURRENT USER
コマンドを実行し,SQLセッションのアクセス権を明示的に付与することが必要です(データベースメソッドが存在する場合)。
v11では,SQLの実行コンテキスト(たとえばトリガ)でCurrent user
を使用することができませんでした。返されるのは,直近のOn SQL Authentication
データベースメソッドで付与されたユーザー名であり,カレントSQLセッションのユーザー名であるとは限らなかったからです。SQLセッションはOn SQL Authentication
データベースメソッドで付与されたアクセス権で実行されていますが,そのアクセス権をCurrent user
で取得できるとは限りません。
v12以降,SQLの実行コンテキストでCurrent user
を使用した場合,SQLセッションのアクセス権がそのまま返されるようになりました。ただし,SQLの実行コンテキスト(たとえばトリガ)でCHANGE CURRENT USER
コマンドを実行した場合,4Dのカレントユーザーが変更され,Current user
とSQLセッションのアクセス権が一致しないことになります。いずれにしても,On SQL Authentication
データベースメソッドでSQLセッションに付与されたアクセス権は,ログアウトするまで有効であり,途中,CHANGE CURRENT USER
コマンドに影響されることはありません。
Courierは,定番のクロスプラットフォーム等幅フォントですが,Windows版はビットマップフォントであることに注意する必要があります。Mac版であれば,Courierフォントが設定されたフォームオブジェクトを印刷することができますが,Windows版は,印刷にDirect2Dが使用されているため,別のフォントが出力されることになります。これは仕様です。
フォームエディターで「透過」プロパティが有効にされている場合,OBJECT SET RGB COLORS
で背景色が指定されたとしても,オブジェクトの背景は塗りつぶされません。背景色にはBackground color none
という定数がありますが,これは「透過」プロパティが有効にされていない場合にだけ使用できる値です。
一方,プロジェクトモードでは,フォームエディターの「透過」プロパティはエクスポートされず,背景色だけがエクスポートされます。したがって,フォームエディターで「透過」プロパティが有効にされているオブジェクトの背景色をプロジェクトモードで再現するためには,OBJECT SET RGB COLORS
で背景色をBackground color none
に指定する必要があります。これは仕様です。
なお,17r5では,OBJECT SET RGB COLORS
が改良され,背景色の指定を省略したり,前景色には触れずに背景色だけを変更できるようになりました(空の文字列を指定)。