1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コレクションのなかでGlobalDictionaryはイベントハンドラが使える??

Last updated at Posted at 2019-03-15

##コレクションのなかでGlobalDictionary(だけ)はイベントハンドラが使える、というがどの程度使えるの?

###collectionsには
elsystem.collections
Dictionaryクラス
Global Dictionaryクラス
Queueクラス
Stackクラス
Vectorクラス
があるのだけれど、Global Dictionaryクラスはイベントハンドラあり。

それが
ItemProcessdEventArgsクラス

###うん、ちゃんと発火するね:当然

###使い方はこんな感じ。


using elsystem;	//datetime
using elsystem.collections;	//Dictionary , Vector

var:GlobalDictionary symbolDictionary(null);

method void AT_initialized( elsystem.Object sender, elsystem.InitializedEventArgs args ) 
begin

	makeSymbolDictionary();
	
end;

method void makeSymbolDictionary()

begin
	symbolDictionary = GlobalDictionary.Create(true , "myDictionary");
	
	symbolDictionary.ItemAdded +=  self.symbolDictionary_updated;
	symbolDictionary.ItemChanged += self.symbolDictionary_updated;
	symbolDictionary.ItemDeleted += self.symbolDictionary_updated;
	symbolDictionary.Cleared += self.symbolDictionary_updated;
	
end;

//ここがハンドラ
{
ItemProcessedEventArgs
Global Dictionary のアップデートの発生時に情報をレポートするために使用してみる
}
method void symbolDictionary_updated(elsystem.Object sender , elsystem.collections.ItemProcessedEventArgs args)
begin
	print(datetime.now.tostring(), "symbolDictionary_updated");


	print(args.Action.ToString()); //added , changed , cleared , deleted , unknown の4タイプあし
	print("symbolDictionary.Count = ",symbolDictionary.Count);
	
	//delete , clear , unknownのときは終わり
	if(args.Action.ToString() ="cleared" or args.Action.ToString() ="deleted" or args.Action.ToString()="unknown") then return;
	
	print(args.key.ToString());
	print(args.Value.ToString());
	
end;


//発火試験

//add
symbolDictionary.Add("8798","アド栗");
symbolDictionary.add("7203","トヨタ");
//発火OK

//changed
if symbolDictionary.Contains("8798") then begin 
	symbolDictionary.items["8798"] = "hogehoge!";
end;

//remove
symbolDictionary.Remove("7203");

//add
symbolDictionary.Add("7049","識学");

//clear
symbolDictionary.Clear();

//add
symbolDictionary.add("7048","ベルトラ");


実行結果は

2019/03/15 19:18:54symbolDictionary_updated
added
symbolDictionary.Count =    2.00
8798
アド栗
2019/03/15 19:18:54symbolDictionary_updated
added
symbolDictionary.Count =    3.00
7203
トヨタ
2019/03/15 19:18:54symbolDictionary_updated
changed
symbolDictionary.Count =    3.00
8798
hogehoge!
2019/03/15 19:18:54symbolDictionary_updated
deleted
symbolDictionary.Count =    2.00
2019/03/15 19:18:54symbolDictionary_updated
added
symbolDictionary.Count =    3.00
7049
識学
2019/03/15 19:18:54symbolDictionary_updated
cleared
symbolDictionary.Count =    0.00
2019/03/15 19:18:54symbolDictionary_updated
added
symbolDictionary.Count =    1.00
7048
ベルトラ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?