Re: About speed



Joanna Carter [TeamB] wrote:
"Robert Giesecke" <spam@xxxxxxxxx> a écrit dans le message de news: 44a01cdf$1@xxxxxxxxxxxxxxxxxxxxxxxxx

| I didn't. :P
| But the moment I write what language could compile it, I would probably get canceled. ;-)
| So let's just imagine it was some mysterious telekinetic phenomenon of me forcing D.Net to
| compile it. *g*

Thank you for your tact and diplomacy :-))


Ok, before someone starts looking sad, here's some nasty hack to get it basically working in native Delphi. *g*

The "almost" abstract base class:
unit uProperty;

interface

type
TProperty = class
private
fName : String;
protected
constructor Create(name : String); overload; virtual; // default constructor
constructor Create(other : TProperty); overload; // copy constructor
public
property Name: String read fName;
procedure AfterConstruction; override;
end;

implementation
uses
SysUtils,
SysConst;

{ TProperty }

procedure TProperty.AfterConstruction;
begin
if ClassType() <> TProperty then // pseudo abstract class...
inherited
else
{$WARNINGS off}
raise EAbstractError.CreateRes(@SAbstractError);
{$WARNINGS on}
end;

constructor TProperty.Create(name: String);
begin
inherited Create();
fName := name;
end;

constructor TProperty.Create(other: TProperty);
begin
inherited Create();
fName := other.Name;
end;

end.


The equivalent to Property<String> would be:

unit uStringProperty;

interface
uses
uProperty;

type
PropertyOfT_DataType = string;

{$INCLUDE PropertyOfT.pas}
TStringProperty = class(TPropertyOfT)
end;
implementation
{$INCLUDE PropertyOfT.pas}
end.

And for Integer:

unit uIntegerProperty;

interface
uses
uProperty;

type
PropertyOfT_DataType = Integer;
{$INCLUDE PropertyOfT.pas}

TIntegerProperty = class(TPropertyOfT)
end;
implementation
{$INCLUDE PropertyOfT.pas}
end.

They could be used this way:

var
Int : Integer;
Str : String;
integerProperty : TIntegerProperty;
stringProperty : TStringProperty;
begin
integerProperty := TIntegerProperty.Create('blabla', 2);
Int := integerProperty.Value;

stringProperty := TStringProperty.Create('blupp', 'some string');
Str := stringProperty.Value;



And now the include file "PropertyOfT.pas", that can be used as unit in its own right. (for debugging, editing, what-so-ever)
But careful, it really is *very* ugly. *g*


You have to define Property_Of_T_test_compile and it will act as a normal unit that uses Integer as the "type parameter":

{$IFDEF Property_Of_T_test_compile}
unit PropertyOfT;

// thanks to Thomas Mueller for his 'Object Pascal Templates' article
// -> http://www.dummzeuch.de/delphi/object_pascal_templates/deutsch.html

// thanks to Rossen Assenov for the original narticle 'Templates in Object Pascal'
// -> http://community.borland.com/article/0,1410,27603,00.html

interface
uses
uProperty;

type
PropertyOfT_DataType = Integer;
{$ENDIF Property_Of_T_test_compile}

{$IFNDEF Property_Of_T_template_2nd_pass}
TPropertyOfT = class(TProperty)
private
fValue: PropertyOfT_DataType;
public
// default constructor
constructor Create(name : String); overload; override;
// initialising constructor
constructor Create(name : String; value : PropertyOfT_DataType); overload;
// copy constructor
constructor Create(other : TPropertyOfT); overload;
property Value : PropertyOfT_DataType
read fValue
write fValue;
end;

{$ENDIF Property_Of_T_template_2nd_pass}

{$IFDEF Property_Of_T_test_compile}
implementation
{$DEFINE Property_Of_T_template_2nd_pass}
{$ENDIF Property_Of_T_test_compile}

{$IFDEF Property_Of_T_template_2nd_pass}

{ TPropertyOfT }

constructor TPropertyOfT.Create(name : String);
begin
inherited Create(name);
end;

constructor TPropertyOfT.Create(name : String; value : PropertyOfT_DataType);
begin
inherited Create(name);
fValue := value;
end;

constructor TPropertyOfT.Create(other : TPropertyOfT);
begin
inherited Create(other);
fValue := other.fValue;
end;

{$IFDEF Property_Of_T_test_compile}
end.
{$ENDIF Property_Of_T_test_compile}
{$ENDIF Property_Of_T_template_2nd_pass}
{$DEFINE Property_Of_T_template_2nd_pass}

.



Relevant Pages

  • Re: About speed
    ... fName: String; ... property Name: String ... fValue: valueT; ... constructor TProperty.Create; ...
    (borland.public.delphi.non-technical)
  • Re: a method to make js have the ability to inherit
    ... but without the implied type-conversion of the string ... that uses the name of a specific constructor. ... programmer has no idea at all what types of object they are ... no reason for ever doing so. ...
    (comp.lang.javascript)
  • Re: Newbie question: Writing your own class
    ... is made by a class's Create constructor method which allocates memory ... FDefinition: string; ... every other descendant of TObject ... Result:= FDefinition; ...
    (comp.lang.pascal.delphi.misc)
  • Re: a method to make js have the ability to inherit
    ... discriminating but without the implied type-conversion of the string ... makes no use of an object's - constructor - property anyway.) ... programs should serve some known purpose known to the programmer. ... var o = Father.prototype; ...
    (comp.lang.javascript)
  • Re: regex into str
    ... people confronted with it to reject python as language. ... Don't get me wrong - there is a lot of decisions to be made in language ... The only thing you really need is a simple constructor for your undoubtly ... Overloading "" as the string ...
    (comp.lang.python)