Voglio attraverso l'ereditarietà modificare l'oggetto TStringList nello specifico voglio modificare la chiamata Add da coś:
function Add(Const S: string): integer; override;
a coś
function Add(index: integer; Const S: string): integer; override;
come posso fare?
Quella che segue è una boza della classe
unit Unit_MyPickListWithIndex;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
TMyPickList = class(TStringList)
private
public
function Add(Const S: string): integer; override;
end;
implementation
{ TMyPickList }
function TMyPickList.Add(Const S: string): integer;
begin
inherited Add(S);
end;
end.
Questo è l'errore che mi da
unit_mypicklistwithindex.pas(15,19) Error: There is no method in an ancestor class to be overridden: "TMyPickList.Add(LongInt, const AnsiString):LongInt;"
prova coś:
unit Unit_MyPickListWithIndex;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
TMyPickList = class(TStringList)
private
public
function Add(index: integer; Const S: string): integer; overload;
end;
implementation
{ TMyPickList }
function TMyPickList.Add(index: integer; Const S: string): integer;
begin
inherited Add(S);
// giusto per fare qualcosa
case index of
0: result := 1;
else
result := -1;
end;
end;
end.