Here is what I have currently:
unit headsup.classes.word; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type { TWord } TWord = class private FCategory : string; FWord : string; FPlayed : boolean; public constructor Create (Category : String; Word : string; Played : boolean); property Word: String Read FWord Write FWord; property Category : String Read FCategory Write FCategory; property Played : Boolean Read FPlayed Write FPlayed; end; { TPlayedWord } TPlayedWord = class(Tword) constructor Create (Category : String; Word : String; Played : boolean; Correct : boolean); override; private FCorrect:boolean; public property Correct : Boolean Read FCorrect Write FCorrect; end; implementation { TPlayedWord } constructor TPlayedWord.Create(Correct: boolean); begin inherited; FPlayed := Played; FCategory := Category; FWord := Word; FCorrect := Correct; end; { TWord } constructor TWord.Create(Category: String; Word: string; Played : boolean); begin FPlayed := Played; FCategory := Category; FWord := Word; end; end.
What am I doing wrong? TPlayedword is inheriting from Tword and I want to be able to pass one additional parameter to TPlayedword - the "Correct" boolean.
Compiler is complaining about Duplicate identifier but when I remove the three original ones it gives me a different error "There is no method in ancestor class to be overridden constructor create(boolean);
Rich
constructor Create (aCategory : String; aWord : String; aPlayed : boolean; aCorrect : boolean);
constructor TPlayedWord.Create (aCategory : String; aWord : String; aPlayed : boolean; aCorrect : boolean);
begin
inherited create(aCategory, aWord, aPlayed);
fCorrect := aCorrect;
end;
"WORD" is a reserved word. It is a Type that is 2 bytes wide..
Use something else in its place. Like AGameWord or something.
At least don't try do make a variable := WORD;
duplicate error because you use parameter name Category, Word, Played while you have property with same name. Rename parameter to different names such as aCategory etc. Override is not needed as parent method is not same in signature and not marked as virtualCode: [Select]constructor Create (aCategory : String; aWord : String; aPlayed : boolean; aCorrect : boolean);
Code: [Select]constructor TPlayedWord.Create (aCategory : String; aWord : String; aPlayed : boolean; aCorrect : boolean);
begin
inherited create(aCategory, aWord, aPlayed);
fCorrect := aCorrect;
end;
Also using word as property name is not recommended as pascal has type with name word.
I've been wondering what the 'a' signifies in the declaration of the procedures?It doesn't mean anything special. Just to escape using the same identifier --- you have declared Category, Word, etc. as property name within the class. Parameter names have significance only within the procedure/function, so it's relatively unimportant how to name them.
By the way I've been wondering what the 'a' signifies in the declaration of the procedures?A consistently applied naming convention can improve readability of code, and go some way to save you from making simple errors.
By the way I've been wondering what the 'a' signifies in the declaration of the procedures? I know 'F' usually means Field.
Besides what Howard wrote, the origin of the "A" prefix convention was to mean the generic English "a" ("one") as in "a category", "a string", "a whatever", etc. That's why sometimes you'll see e.g. "AnObject: TObject". Though, through internacionalization, it has almost lost that original "meaning".
I understand the reasoning - just didn't know if there was a particular meaning for 'A'.. as people prefix class fields with 'F' for Field. Didn't know if there was a similar nomenclature for 'A' or 'a' other than it's just conveniently the first letter of the alphabet! :)
The 'A' or 'a' prefix stands for 'argument' (aka 'parameter' due to 'P' already being used for pointers).
The 'A' or 'a' prefix stands for 'argument' (aka 'parameter' due to 'P' already being used for pointers).I always imagined that the A just was that: a, as in AString meaning "a string", which more or less equals "some string"..
The 'A' or 'a' prefix stands for 'argument' (aka 'parameter' due to 'P' already being used for pointers).
The 'A' or 'a' prefix stands for 'argument' (aka 'parameter' due to 'P' already being used for pointers).