@Rafał D: jest wykonalne, ale jedyne co przychodzi mi do głowy to takie dwa sposoby pokazane poniżej:
Pod VCL z użyciem formatki.
//...
type
TMYTable = array[0..1] of string;
TUseYourBrain = class(TComponent)
private
FTable : TMYTable;
public
constructor Create(AOwner : TComponent); override;
property Table : TMyTable read FTable;
end;
constructor TUseYourBrain.Create;
const
C_Table : TMYTable = ('a', 'b');
begin
inherited create(AOwner);
FTable := C_Table;
end;
procedure TForm1.Button1Click(Sender : TObject);
var
Foo, Bar : TUseYourBrain;
begin
Foo := TUseYourBrain.Create(Self);
Foo.Name := 'Test';
Bar := TUseYourBrain(FindComponent('Test'));
if Bar <> nil then
begin
Caption := Bar.Table[0];
end;
Foo.Free;
end;
//...
Z użyciem modułów VCL, pod aplikacją bez formatki.
//...
{$APPTYPE GUI}
uses
Classes, Controls, Dialogs, SysUtils;
var
TablesList : TList;
type
TMYTable = array[0..1] of string;
TUseYourBrain = class(TComponent)
private
FTable : TMYTable;
public
constructor Create(AOwner : TComponent); override;
property Table : TMyTable read FTable;
end;
constructor TUseYourBrain.Create;
const
C_Table : TMYTable = ('a', 'b');
begin
inherited create(AOwner);
FTable := C_Table;
if TablesList = nil then
begin
TablesList := TList.Create;
end;
TablesList.Add(Self);
end;
function MyFindComponent(AName : string) : TComponent;
var
I : integer;
begin
Result := nil;
for I := 0 to TablesList.Count - 1 do
begin
if SameText(TComponent(TablesList[I]).Name, AName) then
begin
Result := TablesList[I];
Break;
end;
end;
end;
var
Foo, Bar : TUseYourBrain;
begin
Foo := TUseYourBrain.Create(nil);
Foo.Name := 'Test';
Bar := TUseYourBrain(MyFindComponent('Test'));
if Bar <> nil then
begin
ShowMessage(Bar.Table[0]);
end;
Foo.Free;
end.
Co i tak nie zmienia faktu, że gydbyś bardzo chciał to jednak zrobić tylko w WinAPI to musiał byś raczej samodzielnie zaimplementować jakąś listę lub tablicę z komponentami. W ogóle nie wiem po co takie kombinacje. Przecież można faktycznie trzymać to wszystko w tablicy tablic, tak jak już byłó tutaj wspomniane. Konstruktorzy środowiska nie przewidzieli dla potrzeby tworzenia tablicy znalezienia jej po nazwie. To nazwa zmiennej jest - no właśnie adekwatną nazwą. Dlatego jeżeli coś ma być znajdywane po indeksie to albo tablice albo jakaś lista. A jeśli po nazwie, to raczej chyba takim sposobem, jak pokazałem powyżej. Może ktoś jeszcze coś tutaj lepszego doradzi. Chociaż nie wiem, czy zamiast kodować, nie zawracasz sobie głowy pierdółkami. I czy takie kombinacje są w ogóle tego warte :/