2009年8月29日土曜日

Jedi VCL Versionアップ

Delphi 2010の対応です。

ユニットを使うダイアログ


Unitの追加先を選択できるようになってたんだ。
気づかなかった。

Rttiを試して見るその2

前回のポストに引き続いて、メソッドの動的呼び出し。

整数の足し算を行う例です。以下ソース


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button3: TButton;
LabeledEdita: TLabeledEdit;
Label1: TLabel;
LabeledEditb: TLabeledEdit;
Label2: TLabel;
LabelResult: TLabel;
procedure Button3Click(Sender: TObject);
private
{ Private 宣言 }
protected
public
{ Public 宣言 }
function Sakasum(a,b : Integer) : Integer;

end;

var
Form1: TForm1;

implementation
uses
Rtti,TypInfo;

{$R *.dfm}


procedure TForm1.Button3Click(Sender: TObject);
var
ctx : TRttiContext;
rtm : TRttiMethod;
Args : Array of Rtti.TValue;
rst : TValue;
begin
//
ctx := TRttiContext.Create;
rtm := ctx.GetType(Self.ClassType).GetMethod('SakaSum');

if rtm <> nil then
begin
SetLength(Args,2);
//TValueは、演算子Implicitが定義されているので基本的な型は
//変換による代入が可能
Args[0] := StrToInt(LabeledEdita.Text);
Args[1] := StrToInt(LabeledEditb.Text);
rst := rtm.Invoke(Self,Args);
//結果はAsXXXXX関数を使って取り出せる。
Self.LabelResult.Caption := IntToStr(rst.AsInteger);
end;
end;


function TForm1.Sakasum(a, b: Integer): Integer;
begin
Result := a + b;
end;

end.


TValueの使い方が分からなくて結構悩みました。

で、ソースをみたら基本的な型については、
Implicit演算子のオーバーロードが
定義されているのね。

このへんはHelpに書いといて欲しかったです。
(C++ のHELPには書いてあります。)

(英語版のDoc Wikiがメンテナンス中だったので
日本語版でのみ書いていないのかはちょっと不明です。)

また、こちらにDelphi Prismで上記と同様な処理を
記述しました
。

2009年8月28日金曜日

Rttiを試して見る

動的にメソッドを読み出す簡単なプログラムを作ってみました。
プログラムそのものには意味はありません。

プレビュー会に説明があったようにprivateなメソッドは読めませんでした。
メソッドの可視属性を示す型があったので読めてもよいと思ったのですが・・・

また、GetDeclaredMethodsをつかうと自分が宣言したメソッドのみ
リストできます。

以下ソースです。


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
LabeledEdit1: TLabeledEdit;
Button2: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private 宣言 }
//procedure SakaTest2;
protected
//procedure SakaTest1;
procedure SakaTest2;
public
{ Public 宣言 }
procedure SakaTest2;
procedure SakaTest1;
end;

var
Form1: TForm1;

implementation
uses
Rtti,TypInfo;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
ctx : TRttiContext;
rtm : Rtti.TRttiMethod;
obj : TObject;
Args : Array of TValue;
begin
//
ctx := TRttiContext.Create;


//rtm := ctx.GetType(obj).GetMethod(LabeledEdit1.Text);

rtm := ctx.GetType(Self.ClassType).GetMethod(LabeledEdit1.Text);

if rtm <> nil then
begin
//obj := Self;
rtm.Invoke(Self,Args);
end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
ctx : TRttiContext;
rtmary : TArray;
rtm : TRttiMethod;
obj : TObject;
Args : Array of TValue;
rtp : TRttiType;
begin

ctx := TRttiContext.Create;

//rtm := ctx.GetType(obj).GetMethod(LabeledEdit1.Text);
//ctx.FindType()
//rtp := ctx.GetType(Self.ClassType);
//rtp.IsPublicType := false;

rtmary := ctx.GetType(Self.ClassType).GetDeclaredMethods;

ListBox1.Clear;

if rtmary <> nil then
begin
for rtm in rtmary do
begin
ListBox1.Items.Add(rtm.Name);
if rtm.Name = LabeledEdit1.Text then
begin
rtm.Invoke(Self,Args);
end;

end;

end;

end;

procedure TForm1.SakaTest1;
begin
Application.MessageBox('Hello Delphi','First Text');
end;

procedure TForm1.SakaTest2;
begin
Application.MessageBox('Hello Delphi','Second Text');
end;

end.


引数つきのメソッドコールはまた次回

2009年8月26日水曜日

サポートプログラムの配布方法

サポートプログラムの配布方法が
メールによるキー送付に変わった。

いち早く、使用できるのは良いが
やっぱりメディアもあったほうが
良いと思う。

2009年8月25日火曜日

プログラマがマニュアル読まなくどうするの

タイトルだけみて、気分を悪くされた方すみません。

これは、あくまでも自分への戒めのためのタイトルです。

DEKO様はじめ、先日、ご助言頂いた方々どうもありがとうございました。
なお、コメントは非公開と致しますのでご了承願います。

DelphiのHelpがWikiかされたので、ちょっとのぞいていたら
書いてあるんですわ。オブジェクトインスペクタの動作が・・・

ここに

大澤の親分の張本さんに大喝を食らったうえに
タイトルの台詞で叱咤されそうですわ。

しばらくは、懺悔と精進の日々です。

Rad Stduio 2010発売

正式発表があった見たいですね。

とりあえず、値段が据え置きでよかったです。
(スタンダードサポートの更新料も据え置きのようです。)

日本の公式サイトもエンバカデロドメインに移るようで
しばらくはばたばたしそうですね。