interface
uses
Contnrs, Classes;
type
TDoubleObjList = class
private
ObjectList1: TObjectList;
ObjectList2: TObjectList;
FOwnsObjects: Boolean;
procedure SetOwnsObjects(const Value: Boolean);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
property OwnsObjects: Boolean read FOwnsObjects write SetOwnsObjects;
procedure AddData(AObject1, AObject2: TObject);
function IndexOfData1(AIndex: Integer): TObject; overload;
function IndexOfData1(AObject: TObject): Integer; overload;
function IndexOfData2(AIndex: Integer): TObject; overload;
function IndexOfData2(AObject: TObject): Integer; overload;
function Data2GetData1(AObject: TObject): TObject;
function Data1GetData2(AObject: TObject): TObject;
function Count: Integer;
end;
TDoubleString = class
private
Strings1: TStringList;
Strings2: TStringList;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure AddString(AString1, AString2: string);
function IndexOfData1(AIndex: Integer): string; overload;
function IndexOfData1(AString: string): Integer; overload;
function IndexOfData2(AIndex: Integer): string; overload;
function IndexOfData2(AString: string): Integer; overload;
function Data2GetData1(AString: string): string;
function Data1GetData2(AString: string): string;
function Count: Integer;
end;
implementation
{ TDoubleObjList }
procedure TDoubleObjList.AddData(AObject1, AObject2: TObject);
begin
ObjectList1.Add(AObject1);
ObjectList2.Add(AObject2);
end;
procedure TDoubleObjList.Clear;
begin
ObjectList1.Clear;
ObjectList2.Clear;
end;
function TDoubleObjList.Count: Integer;
begin
Result := ObjectList1.Count;
end;
constructor TDoubleObjList.Create;
begin
FOwnsObjects := False;
ObjectList1 := TObjectList.Create;
ObjectList2 := TObjectList.Create;
end;
function TDoubleObjList.Data1GetData2(AObject: TObject): TObject;
begin
Result := ObjectList2.Items[IndexOfData1(AObject)];
end;
function TDoubleObjList.Data2GetData1(AObject: TObject): TObject;
begin
Result := ObjectList1.Items[IndexOfData2(AObject)];
end;
destructor TDoubleObjList.Destroy;
begin
ObjectList1.Free;
ObjectList2.Free;
inherited;
end;
function TDoubleObjList.IndexOfData1(AObject: TObject): Integer;
begin
Result := ObjectList1.IndexOf(AObject);
end;
function TDoubleObjList.IndexOfData1(AIndex: Integer): TObject;
begin
Result := ObjectList1.Items[AIndex];
end;
function TDoubleObjList.IndexOfData2(AObject: TObject): Integer;
begin
Result := ObjectList2.IndexOf(AObject);
end;
function TDoubleObjList.IndexOfData2(AIndex: Integer): TObject;
begin
Result := ObjectList2.Items[AIndex];
end;
procedure TDoubleObjList.SetOwnsObjects(const Value: Boolean);
begin
FOwnsObjects := Value;
ObjectList1.OwnsObjects := Value;
ObjectList2.OwnsObjects := Value;
end;
{ TDoubleString }
procedure TDoubleString.AddString(AString1, AString2: string);
begin
Strings1.Add(AString1);
Strings2.Add(AString2);
end;
procedure TDoubleString.Clear;
begin
Strings1.Clear;
Strings2.Clear;
end;
function TDoubleString.Count: Integer;
begin
Result := Strings1.Count;
end;
constructor TDoubleString.Create;
begin
Strings1 := TStringList.Create;
Strings2 := TStringList.Create;
end;
function TDoubleString.Data1GetData2(AString: string): string;
begin
Result := Strings2.Strings[IndexOfData1(AString)];
end;
function TDoubleString.Data2GetData1(AString: string): string;
begin
Result := Strings1.Strings[IndexOfData2(AString)];
end;
destructor TDoubleString.Destroy;
begin
Strings1.Free;
Strings2.Free;
inherited;
end;
function TDoubleString.IndexOfData1(AIndex: Integer): string;
begin
Result := Strings1.Strings[AIndex];
end;
function TDoubleString.IndexOfData1(AString: string): Integer;
begin
Result := Strings1.IndexOf(AString);
end;
function TDoubleString.IndexOfData2(AString: string): Integer;
begin
Result := Strings2.IndexOf(AString);
end;
function TDoubleString.IndexOfData2(AIndex: Integer): string;
begin
Result := Strings2.Strings[AIndex];
end;
end.