Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why certain parameters are prefixed with an "A" in Delphi?

In Delphi coding standard, what is the rule to add an A prefix before parameter name in functions/procedures?

For example:

constructor Create(AOwner: TComponent); override;
constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); virtual;
procedure AddAncestor(Component: TComponent); //No A prefix, why?

function FindClass(const ClassName: string): TPersistentClass; //No A prefix, why?
function GetClass(const AClassName: string): TPersistentClass;
procedure StartClassGroup(AClass: TPersistentClass);
procedure GroupDescendentsWith(AClass, AClassGroup: TPersistentClass);

Ton more examples are in Delphi common classes (see Classes, Forms, etc.). Hence my question - what is the rule when to add and when not?

like image 511
Kromster Avatar asked Dec 23 '11 05:12

Kromster


2 Answers

'A' is for 'Argument'. Also, 'F' is for 'Field', 'T' is for 'Type', 'E' is for 'Exception', 'I' is for 'Interface'.

There is no rule when to add 'A' prefix and when not.

like image 133
kludg Avatar answered Oct 12 '22 12:10

kludg


It's typically done when there would be a clash of names. For example in the TComponent constructor imagine if it was written:

constructor TComponent.Create(Owner: TComponent)

Now the Owner parameter hides the Owner property of the instance. To refer to the property you would have to write Self.Owner.

You will probably find, in the VCL sources, that the A prefix is used when there is such a clash, and not used when there is not. But there will be inconsistency in the application of this convention.

I rather hoped that the Embarcadero Pascal style guide would say something on the matter, but sadly it remains silent.

Personally I never use an A prefix in code that I write. In my experience hiding is invariably fine because what you typically want to refer to is the parameter rather than the instance member. If you ever need to refer to the instance member then Self.Name can disambiguate.

So, there's no rule, just convention determined by personal preference. Make your own choice and stick to it. Consistency is far more important than whether or not you opt to use such a naming convention.

like image 29
David Heffernan Avatar answered Oct 12 '22 14:10

David Heffernan