Delphi のバックグラウンドから来て、私は特定のスーパークラスのクラス参照/ポインターを持つことができることに慣れています。例:
#!pas
var
niceVar: class of TClassOne; // Delphi style
badVar: class; // Only? allowed AS3 style to the best of my knowledge
begin
niceVar := x;
badVar := x;
niceVar.staticMethodSpecificToTClassOne;
TClassOne(badVar).staticMethodSpecificToTClassOne;
end;
これが意味することは、変数を特定のクラスにキャストする必要がないということです。それらは事前に正しいクラスです。これは、適切なメンバーがアクセスされていることを確認するためにコンパイル時のチェックを実行できることも意味します。niceVar がメソッドに渡された場合、niceVar が実際にクラス TClassOne であることを確認する必要はありません。
#!pas
procedure test(var x: class of TClassOne);
begin
x.someStaticMethod(true);
end;
// An entry point
var
niceVar: TClassTwo; // Does not inherit from TClassOne
begin
test(niceVar); // Error - niceVar does belong to the TClassOne "family"
end;
したがって、オブジェクトを格納する変数が特定の型のものである可能性があり、そのクラスまたはそのサブクラスのオブジェクトのみが受け入れられるのと同じように、「AClass のクラス」では、特定のクラスの変数を特定のクラスへの参照に制限することができます。クラスまたはそれから継承されたもの。
どういうわけかそれが理にかなっていることを願っています。「スーパークラスのクラス」全体の特定の命名法については知りません。
したがって、クラス型の変数/プロパティ/パラメーターを使用してもマスタードをカットしないため、AS3で同じことをしたいと思います。そのようなものは、すべてのオブジェクト変数/プロパティ/パラメーターを、適切な特定の型ではなく、単純にオブジェクトにするようなものです。
編集 #1 - 2011-02-14 13:34 ここでは構文の強調表示がめちゃくちゃです。コードを Object Pascal として認識させたい。これを楽しみにしています。
編集 #2 - 2011-02-14 15:11 AS3 でこれを使用して達成したいことの例を次に示します。
現在のコード
public function set recordClass(aRecordClass: Class): void
{
if (!extendsClass(aRecordClass, TRecord))
{
throw new Error("TDBTable - Invalid record class passed.");
return;
}
_recordInstance = new aRecordClass(this); // Compiler has no idea of the classes constructor signature, but allows this regardless.
}
できるようになりたいこと
public function set recordClass(aRecordClass: TRecordClass): void
{
_recordInstance = new aRecordClass(this); // Compiler will know that I am creating a TRecord
}