[fpc-pascal] A better way?

Ryan Joseph ryan at thealchemistguild.com
Fri Apr 15 14:20:46 CEST 2016


> On Apr 15, 2016, at 7:03 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> 
> Again, you're fighting against design principles of the language. It's just as if you'd want to have virtual class methods in C++…

Agreed. Everyone has their own list of things they want their language to do I guess. Maybe I got spoiled with the typeless “id” type from Objective-C that let me have little work arounds for things like this. Not having a dictionary type after using PHP hurts also. ;)

Here’s another option I thought of. If the type casting was of a serious quantity doing this could save time and improve readability of code. 

unit unitA;

interface

type

class TClassA
private
 FClassBObject: TObject;
public
 procedure SomeProc;
end;

implementation

uses unitB;

type
 TClassAHelper = class helper for TClassA
  function aClassBObject: TClassB;
 end;

function TClassAHelper.aClassBObject: TClassB;
begin
 result := TClassB(FClassBObject)
end;

procedure TClassA.SomeProc;
begin
 aClassBObject.OtherProc;
end;

end.

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list