unit OBGLFunc;

interface

uses Classes;

type
 TNamedListItem=record
  Name:string;
  Value: pointer;
 end;
 TNamedList=class(TList)
  private
   function GetValue(const AName:string):pointer;
   procedure SetValue(const AName:string; const AValue:pointer);
  public
  // function NameOf(AValue:string):string;
   function IndexOfValue(AValue:pointer):Integer;
   function IndexOfName(AName:string):Integer;
   property Values[const AName:string]:pointer read GetValue write SetValue;
   constructor Create;
   destructor Free;
//   property Values[const AIndex:Integer]:string read GetValueI write SetValueI;
 end;

implementation

function TNamedList.IndexOfName(AName:string):Integer;
var i:integer;
begin
 Result := -1;
 if Count<1 then exit;
 for i := 0 to Count-1 do if TNamedListItem(Items[i]^).Name=AName then begin
  Result := i;
  break;
 end;
end;

function TNamedList.IndexOfValue(AValue:pointer):Integer;
var i:integer;
begin
 Result := -1;
 for i := 0 to Count-1 do if TNamedListItem(Items[i]^).Value=AValue then begin
  Result := i;
  break;
 end;
end;

procedure TNamedList.SetValue(const AName:string; const AValue:pointer);
var id:integer; ip:^TNamedListItem;
begin
 id := IndexOfName(AName);
 if id<0 then begin
  //GetMem(ip, SizeOf(TObjProp));
  New(ip);
  ip^.Name := AName;
  ip^.Value := AValue;
  Add(ip);
 end else begin
  ip := Items[id];
  ip^.Value := AValue;
 end;
end;

function TNamedList.GetValue(const AName:string):pointer;
var r:integer;
begin
 r := IndexOfName(AName);
 if (r<0) then begin
  Result := nil;
  exit;
 end;
 Result := TNamedListItem(Items[r]^).Value;
end;

constructor TNamedList.Create;
begin
end;

destructor TNamedList.Free;
var i:integer;
begin
 for i := 0 to Count-1 do FreeMem(Items[i]);
 inherited Free;
end;


end.
 