Uses Types, SysConst, SysUtils;
Type TMyType = Integer;
TMyStringIndizeInnerArray =
Array of Record
Name:
String;
Data: TMyType;
End;
TMyStringIndizeArray =
Record
Private
_A: TMyStringIndizeInnerArray;
Procedure SetData(
Const Name:
String;
Const Data: TMyType);
Function GetData(
Const Name:
String): TMyType;
Procedure SetDataI(
Index: Integer;
Const Data: TMyType);
Function GetDataI(
Index: Integer): TMyType;
Function GetName (
Index: Integer):
String;
Public
Class Operator Implicit(
Const A: TMyStringIndizeInnerArray): TMyStringIndizeArray;
Class Operator Implicit(
Const Rec: TMyStringIndizeArray): TMyStringIndizeInnerArray;
Property Data[
Const Name:
String]: TMyType
Read GetData
Write SetData;
Default;
Property Data[
Index: Integer]: TMyType
Read GetDataI
Write SetDataI;
Default;
Property Name[
Index: Integer]:
String Read GetName;
End;
Procedure TMyStringIndizeArray.SetData(
Const Name:
String;
Const Data: TMyType);
Var i: Integer;
Begin
i := 0;
While (i < Length(_A))
and (_A[i].
Name <>
Name)
do Inc(i);
If (i >= Length(_A))
Then Begin
SetLength(_A, i + 1);
_A[i].
Name :=
Name;
End;
_A[i].Data := Data;
End;
Function TMyStringIndizeArray.GetData(
Const Name:
String): TMyType;
Var i: Integer;
Begin
i := High(_A);
While _A[i].
Name <>
Name do Dec(i);
Result := GetDataI(i);
End;
Procedure TMyStringIndizeArray.SetDataI(
Index: Integer;
Const Data: TMyType);
Begin
If (
Index >= 0)
and (
Index < Length(_A))
Then _A[
Index].Data := Data
Else Raise ERangeError.CreateRes(@SRangeError);
End;
Function TMyStringIndizeArray.GetDataI(
Index: Integer): TMyType;
Begin
If (
Index >= 0)
and (
Index < Length(_A))
Then Result := _A[
Index].Data
Else Raise ERangeError.CreateRes(@SRangeError);
End;
Function TMyStringIndizeArray.GetName(
Index: Integer):
String;
Begin
If (
Index >= 0)
and (
Index < Length(_A))
Then Begin
If _A[
Index].
Name <> '
'
Then Result := _A[
Index].
Name
Else Result := IntToStr(
Index);
End Else Raise ERangeError.CreateRes(@SRangeError);
End;
Class Operator TMyStringIndizeArray.Implicit(
Const A: TMyStringIndizeInnerArray): TMyStringIndizeArray;
Begin
Result._A := A;
End;
Class Operator TMyStringIndizeArray.Implicit(
Const Rec: TMyStringIndizeArray): TMyStringIndizeInnerArray;
Begin
Result := Rec._A;
End;
procedure TForm1.FormCreate(Sender: TObject);
Var A: TMyStringIndizeArray;
Begin
//SetLength(A, 5); // geht leider doch nicht ... blöder Var-Parameter -.-°
A['
himi'] := 0815;
If A['
himi'] = A[0]
Then ;
If Length(A) = 1
Then ;
// aber warum geht das auch nicht? o.O
End;