unit constarray;
interface
uses classes;
type
TMyTableRecord = class
fName : string;
fSearchString : string;
end;
TMyTableSearch = class
fRecords : TList;
fRec : TMyTableRecord;
private
procedure FillRecords;
public
constructor create;
destructor destroy; override;
function GetRecord(const aName : string) : boolean;
function Table(const aIndex : smallint) : string;
function Get(const aName : string; const aValue : smallint) : string;
end;
implementation
{ TMyTableSearch }
constructor TMyTableSearch.create;
begin
fRecords := TList.Create;
FillRecords;
end;
destructor TMyTableSearch.destroy;
var index : smallint;
begin
for index := 0 to fRecords.Count - 1 do
TMyTableRecord(fRecords[index]).Free;
fRecords.Free;
inherited;
end;
procedure TMyTableSearch.FillRecords;
procedure Add(const aName, aValue : string);
var Rec : TMyTableRecord;
begin
Rec := TMyTableRecord.Create;
rec.fName := aName;
rec.fSearchString := aValue;
fRecords.Add(Rec);
end;
begin
Add('V021111','V17,V08,V19');
Add('V021112','V10,V17,V08,V19');
Add('V021121','V08,V09,V19');
Add('V021122','V10,V08,V09,V19');
Add('V021131','V30,V08,V09');
Add('V021132','V10,S21,V08,V09');
Add('V021211','V08,V17,V12,V19');
Add('V021212','V08,V10,V17,V12,V19');
Add('V021221','V08,V09,V19');
Add('V021222','V08,V10,V09,V19');
Add('V021231','V08,S21,V09');
Add('V021232','V08,V10,S21,V09');
Add('V021311','V08,V12,V19');
Add('V021312','V08,V10,V12,V19');
Add('V021321','V08,V09,V19');
Add('V021322','V08,V10,V09,V19');
Add('V021331','V08,S21,V09');
Add('V021332','V08,V10,S21,V09');
end;
function TMyTableSearch.Get(const aName: string;
const aValue: smallint): string;
begin
GetRecord(aName);
result := Table(aValue)
end;
function TMyTableSearch.getRecord(const aName : string) : boolean;
var index : smallint;
begin
fRec := nil;
result := false;
for index := 0 to fRecords.Count - 1 do
begin
if TMyTableRecord(fRecords[index]).fName = aName then
begin
fRec := TMyTableRecord(fRecords[index]);
result := true;
end;
end;
end;
function TMyTableSearch.Table(const aIndex: smallint): string;
var sl : TStringlist;
begin
sl := TStringlist.create;
result := '';
try
if fRec <> nil then
begin
sl.CommaText := frec.fSearchString;
if aIndex <= sl.Count then
result := sl[aindex - 1]
end;
finally
sl.Free;
end;
end;
end.