Discussion:
Class inheriting fields
(too old to reply)
Skybuck Flying
2015-01-05 03:06:28 UTC
Permalink
Hello,

It would be very nice if a class could inherited from a record.

Then the record type can be used for optimized code and such, well the class
can be used for flexibility but still have the same fields.

Either class can copy fields to a record later or, or perhaps class and
record could even be assignment compatible so that copieing can be done
automatically.

Or perhaps even better, compiler treats passing a class to a record type as
a "value copy" and automatically copies or supplies fields, for example in
the case of a var parameter, the pointer of the class is automatically
dereferenced. This would make Delphi a whole lot more flexible... perhaps
even more powerfull.

The base of oo design could then be records for fast access to fields, while
later on they can be wrapped in classes where references are needed more.

// *** Begin of Test Program ***

{

Test class inheriting fields from record.

version 0.01 created on 5 january 2015 by Skybuck Flying

Would be nice if class would at least inherit fields from record, as well as
properties.

}

program TestProgram;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils;

type
TMyRecord = record
private
mMyField : integer;
public
property MyField : integer read mMyField write mMyField;
end;

TMyClass = class(TMyRecord) // error class type required

end;


begin
try
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

// *** End of Test Program ***

Bye,
Skybuck.
Skybuck Flying
2015-01-05 03:07:08 UTC
Permalink
(Woops forgot to type in subject line completely, there done...)

Hello,

It would be very nice if a class could inherited from a record.

Then the record type can be used for optimized code and such, well the class
can be used for flexibility but still have the same fields.

Either class can copy fields to a record later or, or perhaps class and
record could even be assignment compatible so that copieing can be done
automatically.

Or perhaps even better, compiler treats passing a class to a record type as
a "value copy" and automatically copies or supplies fields, for example in
the case of a var parameter, the pointer of the class is automatically
dereferenced. This would make Delphi a whole lot more flexible... perhaps
even more powerfull.

The base of oo design could then be records for fast access to fields, while
later on they can be wrapped in classes where references are needed more.

// *** Begin of Test Program ***

{

Test class inheriting fields from record.

version 0.01 created on 5 january 2015 by Skybuck Flying

Would be nice if class would at least inherit fields from record, as well as
properties.

}

program TestProgram;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils;

type
TMyRecord = record
private
mMyField : integer;
public
property MyField : integer read mMyField write mMyField;
end;

TMyClass = class(TMyRecord) // error class type required

end;


begin
try
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

// *** End of Test Program ***

Bye,
Skybuck.

Loading...