Re: About speed
- From: Robert Giesecke <Spam@xxxxxxxxx>
- Date: Mon, 26 Jun 2006 23:40:15 +0200
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}
.
- Follow-Ups:
- Re: About speed
- From: Joe Hendricks
- Re: About speed
- References:
- Re: About speed
- From: Árpád Soós
- Re: About speed
- From: Oliver Townshend
- Re: About speed
- From: Don Strenczewilk
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Craig Stuntz [TeamB]
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Bryce K. Nielsen
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Robert Giesecke
- Re: About speed
- From: Barry Kelly
- Re: About speed
- From: Alex
- Re: About speed
- From: Robert Giesecke
- Re: About speed
- From: Alex
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: I.P. Nichols
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Ingvar Nilsen
- Re: About speed
- From: Michael C.
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Robert Giesecke
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- From: Robert Giesecke
- Re: About speed
- From: Joanna Carter [TeamB]
- Re: About speed
- Prev by Date: Re: Will Delphi 2006 trail work on XP Home Edition?
- Next by Date: Re: About speed
- Previous by thread: Re: About speed
- Next by thread: Re: About speed
- Index(es):
Relevant Pages
|
|