Autor Beitrag
Takeshi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 10.08.03 01:10 
Hallo!

schwierig eine geeignete Überschrift zu finden :roll:

Folgendes kenne ich noch aus VBasic:
Man gibt einer Reihe von Objekten, beispielsweise Images die Namen Image[1], Image[2], Image[3] usw und kann sie dann als Feld, bzw Array of TImage behandeln.
Und das schon im Object Inspector

Meine Frage ist nun, ob und wie das in Delphi möglich ist. Es wäre schon sehr praktisch :?

viele Grüße, vielen Dank, Takeshi
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 10.08.03 09:15 
für Images gibt es die Kompo Imagelist auf der Win32-Reiterkarte.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Takeshi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 10.08.03 14:00 
das war es glaube ich nicht, was ich suche
Ich gebe mal ein Beispiel (ohne besonderen Sinn)

user defined image

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var PictureFiles:TStrings;

procedure TForm1.LoadPictures;
var i:integer;
begin
for i:= 0 to 3 do begin
  Image[i].Picture.LoadFormFile(PictureFiles[i]);
  Button[i].Caption:=ExtractFileName(PictureFiles[i]);
  end;
end;


Auf ungefähr so etwas wollte ich hinaus. In VBasic konnte man eben im Objekt Inspektor den Images die Namen Image[1], Image[2], usw und den Buttons die Namen Button[1], Button[2], Button[3] geben.
Wenn dass jetzt ganz naiv war so etwas auch in Delphi vorzuhaben, dann sag mir bitte jemand dass das nicht geht :cry:

Gruß, Takeshi
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 10.08.03 14:12 
ok, falsch verstanden.
da gäbe es mehrere Möglichkeiten: wenn mehr wird evtl Frames, bevorzuge ich, weil das ist übersichtlicher.

Deine Variante würde funktionieren, wenn du die Images dynamisch zur Laufzeit erzeugst und diese in einem Array speicherst Suche in: Delphi-Forum, Delphi-Library LAUFZEIT ERSTELLEN (hoffe das geht ;) ) oder du nutzt Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: So 10.08.03 14:36 
Dazu bräuchte man eine ganz besondere und dafür zugeschnittene Compiler Magic, die der Delphi Compiler dank seiner Vielseitigkeit nicht bieten kann.

Du kannst dir deine Array jedoch zur Laufzeit selbst aufbauen:

Hier eine automatische Funktion:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
{ BuildComponentArray baut ein Array[StartIndex..EndIndex] für Komponenten, die
  der Namensform Button1, Button2, ..., ButtonN folgen, auf.

  Owner      ist der Besitzer der Komponenten
  Prefix     gibt an, welchen Namen die Komponenten (ohne die laufende Nummer)
             haben
  A          gibt das zu erzeugende dyamische Array an. Das erste Element
  StartIndex gibt an, ab welchem Index zu suchen begonnen wird
  EndIndex   gibt an, bis zu welchem Index gesucht wird. Ist EndIndex = -1,
             werden alle Komponenten, die eine durchgehende Nummerierung von
             StartIndex ab haben, in das Array aufgenommen.

  Für A können alle dynamischen Arrays benutzt werden, deren Elemente vom Typ
  TComponente oder abgeleiteten Klassen sind. }


procedure BuildComponentArray(Owner: TComponent; const Prefix: string;
  var A {: array of TComponent derived classes};
  StartIndex: Integer = 1; EndIndex: Integer = -1);
const
  Delta = 10;
type
  PComponentDynArray = ^TComponentDynArray;
  TComponentDynArray = array of TComponent;
var
  Index, Len: Integer;
  Component: TComponent;
  CompArray: PComponentDynArray;
begin
  if (EndIndex <> -1and (StartIndex > EndIndex) then
    raise Exception.Create('Invalid StartIndex or EndIndex values.');

  CompArray := PComponentDynArray(@A);
  SetLength(CompArray^, Delta * 2);
  Len := 0;

  Index := StartIndex;
  repeat
    Component := Owner.FindComponent(Prefix + IntToStr(Index));
    if Component <> nil then
    begin
      Inc(Len);
      if Len >= Length(CompArray^) then
        SetLength(CompArray^, Length(CompArray^) + Delta);
      CompArray^[Len] := Component;
    end
    else
      if (EndIndex = -1or (Index >= EndIndex) then
        Break;

    Inc(Index);
  until False;
  if Len > 0 then Inc(Len);
  SetLength(CompArray^, Len);
end;

//------
private
  FImages: array of TImage;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  BuildImageArray(Self, 'Image', FImages);
  FImages[1].Picture.LoadFromFile('C:\Test\Test.bmp');
end;

_________________
Ist Zeit wirklich Geld?


Zuletzt bearbeitet von AndyB am So 10.08.03 18:37, insgesamt 1-mal bearbeitet
Takeshi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: So 10.08.03 18:23 
vielen dank :D
ich bin mit FindComponent schon zufrieden, ich muss das nicht in einem Array haben, wenn ich die Sachen auch so ansprechen kann.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var PictureFiles:TStrings; 

procedure TForm1.LoadPictures; 
var i:integer;
begin
for i:= 0 to 3 do begin
  with TImage(FindComponent('Image'+IntToStr(i+1))) do
    Picture.LoadFromFile(PictureFiles[i]);
  with TButton(FindComponent('Button'+IntToStr(i+1))) do
    Caption:=ExtractFileName(PictureFiles[i]);
  end;
end;