Sind in FPC auch Record-Methoden möglich?
Wenn ja, dann würde ich eine Verwendung dieser Vorschlagen.
Delphi-Quellcode:
TMyRecord = record
myArray: TDynIntegerArray;
procedure Add(Value: Integer);
end;
procedure TMyRecord.Add(Value: Integer);
var
i: Integer
begin
i := Length(myArray);
SetLength(myArray, i + 1);
myArray[i] := Value;
end;
Delphi-Quellcode:
TTestCases = record
FData: Array of TData;
...
property Data[index: Integer]: TData read GetData; default;
function Add(Pattern, Text: String; occurences: array of Integer): Integer;
end;
// == Defining test cases == //
// 1. testcase (pattern + text is identical)
testCases.Add('aababaab', testCases[0].pattern, [1]);
// 2. testcase (pattern occures somewhere in the middle)
testCases.Add('aababaab', 'aaa' + testCases[1].pattern + 'aaa', [4]);
// 3. testcase: (pattern does not occur in the string)
testCases.Add('aababaab', 'aaaaaabbbbbbbbaaaabbbbhhhhhaaadddd', []);
// 4. testcase: (pattern occures several time without overlapping each other)
testCases.Add('aababaab', 'aa' + testCases[3].pattern + 'a' + testCases[3].pattern, [3, 12]);
// 5. testcase (pattern occures several times with overlapping each other)
testCases.Add('aababaab', 'aababaababaab', [1, 6]);
// DONE: Building test cases
Wobei sich das Ganze auch über eine Klasse lösen liese.