Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TForm1 = class(TForm)
- procedure FormShow(Sender: TObject);
- end;
- TTestClass = class
- public
- class procedure TestMethod(); virtual;
- end;
- TTestDerivedClass = class(TTestClass)
- public
- class procedure TestMethod(); override;
- end;
- TTestMetaClass = class of TTestClass;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- class procedure TTestClass.TestMethod();
- begin
- Application.MessageBox('base', 'Message');
- end;
- class procedure TTestDerivedClass.TestMethod();
- begin
- Application.MessageBox('descendant', 'Message');
- end;
- procedure TForm1.FormShow(Sender: TObject);
- var
- sample: TTestMetaClass;
- begin
- sample := TTestClass;
- sample.TestMethod;
- sample := TTestDerivedClass;
- sample.TestMethod;
- end;
- class Root {
- public static virtual string TestMethod() {return "Root"; }
- }
- TRootClass = class of TRoot; // Here is the typed type declaration
- class Derived : Root {
- public static overide string TestMethod(){ return "derived"; }
- }
- class Test {
- public static string Run(){
- TRootClass rc;
- rc = Root;
- Test(rc);
- rc = Derived();
- Test(rc);
- }
- public static Test(TRootClass AClass){
- string str = AClass.TestMethod();
- Console.WriteLine(str);
- }
- }
- class Car
- {
- public static int TyreCount = 4;
- public virtual int GetTyreCount() { return TyreCount; }
- }
- class Tricar : Car
- {
- public static new int TyreCount = 3;
- public override int GetTyreCount() { return TyreCount; }
- }
- ...
- Car[] cc = new Car[] { new Tricar(), new Car() };
- int t0 = cc[0].GetTyreCount(); // t0 == 3
- int t1 = cc[1].GetTyreCount(); // t1 == 4
- public abstract class HouseDeed : Item
- {
- public static int m_price = 0;
- public abstract int Price { get; }
- /* more impl here */
- }
- public class FieldStoneHouseDeed : HouseDeed
- {
- public static new int m_price = 43800;
- public override int Price { get { return m_price; } }
- /* more impl here */
- }
- public class SmallTowerDeed : HouseDeed
- {
- public static new int m_price = 88500;
- public override int Price { get { return m_price; } }
- /* more impl here */
- }
- public interface ISumable<T>
- {
- static T Add(T left, T right);
- }
- public T Aggregate<T>(T left, T right) where T : ISumable<T>
- {
- return T.Add(left, right);
- }
- public static class Static<T> where T : new()
- {
- public static Value = new T();
- }
- public interface ISumable<T>
- {
- T Add(T left, T right);
- }
- public T Aggregate<T>(T left, T right) where T : ISumable<T>, new()
- {
- return Static<T>.Value.Add(left, right);
- }
Add Comment
Please, Sign In to add comment