method MainForm.button1_Click(sender: System.Object; e: System.EventArgs); begin var myguid := System.Guid.NewGuid; label1.Text := myguid.ToString(); end;
DelphiXE(Wi32)には、System.Guid構造体と同じように動作するHelperが実装されて
います。
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs); begin var myguid := System.Guid.NewGuid; label1.Text := myguid.ToString(); end;
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs); var ProcessList : array of System.Diagnostics.Process; begin ProcessList := System.Diagnostics.Process.GetProcesses(); for each ps : System.Diagnostics.Process in ProcessList do begin listbox1.Items.Add(ps.ProcessName); end; end;
method MainForm.buttonExecGetFile_Click(sender: System.Object; e: System.EventArgs);
var
FileList : Array of String;
FileName : String;
begin
Self.listBoxResult.Items.Clear();
if Self.checkBoxFindSubDir.Checked then
begin
FileList := System.IO.Directory.GetFiles(Self.textBoxStartPath.Text,'*',System.IO.SearchOption.AllDirectories);
end
else
begin
FileList := System.IO.Directory.GetFiles(Self.textBoxStartPath.Text,'*',System.IO.SearchOption.TopDirectoryOnly);
end;
For FileName in FileList do
begin
listBoxResult.Items.Add(FileName);
end;
end;
method MainForm.BuildSql(obj : System.Object) : String;
var
FldList : String;
ValList : String;
t : System.Type;
PropArry : Array of PropertyInfo;
pv : Object;
begin
//渡された型を取り出して
t := obj.GetType();
//プロパティの一覧を取得する
PropArry := t.GetProperties();
//全てのフィールド(プロパティ)を操作してInsert分を作成
FldList := '';
ValList := '';
for each Prop : PropertyInfo in PropArry do
begin
FldList := FldList + Prop.Name + ',';
pv := Prop.GetValue(obj, nil);
//Value句 文字列は''で囲
if (pv.GetType().Name = 'String') then
begin
ValList := ValList + ''''+ pv.ToString() + ''',';
end
else
begin
ValList := ValList + pv.ToString() + ",";
end;
end;
Var Sb := new System.Text.StringBuilder();
Sb.AppendLine('INSERT INTO ' + t.Name + '(' + FldList.Remove(FldList.Length - 1) + ')');
Sb.AppendLine('Values (' + ValList.Remove(ValList.Length - 1) + ')');
Result := Sb.ToString();
end;
private String BuildSQL(object o)
{
//渡された型を取り出して
Type t = o.GetType();
//プロパティの一覧を取得する
System.Reflection.PropertyInfo[] PropArry = t.GetProperties();
//全てのフィールド(プロパティ)を操作してInsert分を作成
string FldList = "";
string ValList = "";
foreach (PropertyInfo Prop in PropArry)
{
FldList = FldList + Prop.Name + ",";
Object pv = Prop.GetValue(o, null);
//Value句 文字列は''で囲
if (pv.GetType().Name == "String")
{
ValList = ValList + "'" + pv.ToString() + "',";
}
else
{
ValList = ValList + pv.ToString() + ",";
}
}
StringBuilder Sb = new StringBuilder();
Sb.AppendLine("INSERT INTO " + t.Name + "(" + FldList.Remove(FldList.Length - 1) + ")");
Sb.AppendLine("Values (" + ValList.Remove(ValList.Length - 1) + ")");
return (Sb.ToString());
}
namespace WindowsApplication1;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Linq,
System.Windows.Forms,
System.ComponentModel,
System.Reflection,
SakaTestSpace;
type
///
/// Summary description for MainForm.
///
MainForm = partial class(System.Windows.Forms.Form)
private
method button1_Click(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
var
SakaTestIntf : SakaTestSpace.ISakaTest;
CreateClassName : String;
t : System.Type;
obj : System.Object;
Assem : System.Reflection.Assembly;
begin
//使用するアセンブリをロードする
Assem := System.Reflection.Assembly.Load('ClassLibrary1');
t := Assem.GetType('SakaTestSpace.' + textBox1.Text);
obj := Activator.CreateInstance(t);
if obj <> nil then
begin
SakaTestIntf := (obj As SakaTestSpace.ISakaTest);
if SakaTestIntf <> nil then
begin
label3.Text := SakaTestIntf.SayMessage();
end;
end;
end;
end.
namespace SakaTestSpace;
interface
uses
System.Collections.Generic,
System.Linq,
System.Text;
type
ISakaTest = public interface
method SayMessage : String;
end;
type
TSakaTest = public class(ISakaTest)
private
protected
public
method SayMessage : String ; virtual;
end;
TSakaTest1 = public class(TSakaTest)
private
protected
public
method SayMessage : String; override;
end;
TSakaTest2 = public class(TSakaTest)
private
protected
public
method SayMessage : String; override;
end;
implementation
method TSakaTest.SayMessage : String;
begin
Result := "";
end;
method TSakaTest1.SayMessage : String;
begin
Result := 'Delphi Prism First Message';
end;
method TSakaTest2.SayMessage : String;
begin
Result := 'Delphi Prism Second Message';
end;
end.
namespace WindowsApplication1;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Linq,
System.Windows.Forms,
System.ComponentModel,
System.Reflection;
type
///
/// Summary description for MainForm.
///
MainForm = partial class(System.Windows.Forms.Form)
private
method button1_Click(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
method SakaSum(a, b : Integer) : Integer;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
var
rtm : System.Reflection.MethodInfo;
Args : Array of System.Object;
Rst : System.Object;
MyType : System.Type;
begin
MyType := System.Type.GetType('WindowsApplication1.' + Self.Name);
rtm := MyType.GetMethod('SakaSum');
if rtm <> nil Then
begin
Args := new System.Object[2];
Args[0] := Convert.ToInt32(textBox1.Text);
Args[1] := Convert.ToInt32(textBox2.Text);
Rst := rtm.Invoke(Self,Args);
label5.Text := Rst.ToString();
end;
end;
method MainForm.SakaSum(a, b : Integer) : Integer;
begin
Result := a + b;
end;
end.