Why do some parameters have the prefix "A" in Delphi?

In the Delphi coding standard, what is the rule of adding the prefix A before the 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); 

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

+8
coding-style delphi
source share
2 answers

This usually happens when a name clash occurs. For example, in the TComponent constructor, imagine if it was written:

 constructor TComponent.Create(Owner: TComponent) 

The Owner parameter now hides the instance's Owner property. To reference a property, you need to write Self.Owner.

In VCL sources, you will probably find that the prefix A is used when there is such a collision, and is not used when it is not. But there will be inconsistency in the application of this agreement.

I rather hoped that the Embarcadero Pascal style guide would say something about this, but unfortunately it remains silent.

Personally, I never use the A prefix in the code I write. In my experience, hiding is invariably beautiful because what you usually want to call is a parameter, not a member of an instance. If you ever need to refer to an instance member, then Self.Name can be ambiguous.

So, there is no rule, just the agreement is determined by personal preference. Make your choice and stick to it. Consistency is far more important than whether you choose to use such a naming convention.

+6
source share

'A' for the argument. In addition, 'F' for 'Field', 'T' for 'Type', 'E' for 'Exception', 'I' for 'Interface'.

There is no rule when you need to add the prefix "A", and when not.

+17
source share

All Articles