Autor Beitrag
Arbengie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mi 31.03.10 14:20 
Hi, und zwar würde ich gerne wissen, ob es möglich ist mehrere Labels gleichzeitig auszuwählen und denen eine Aufgabe zu weisen...

z.B.:
-Habe 3 Labels (Label1,Label2,Label3)
-Mit einem Befehl, dass sich alle 10 Pixel nach rechts verschieben
-Sodass man nich für jedes Label schreiben muss:
ausblenden Delphi-Quelltext
1:
2:
3:
Label1.Left := Label1.Left + 10
Label2.Left := Label2.Left + 10
Label3.Left := Label3.Left + 10


Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 31.03.10 14:26 
Wenn die Labels so durchnummeriert sind, kannst du in einer Schleife FindComponent benutzen.

_________________
We are, we were and will not be.
martin300
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mi 31.03.10 15:25 
Bzw. hier www.delphiforum.de/v...+dynamisch+erstellen ist noch eine andere Möglichkeit, wenn du es gleich bei der Erstellung machen möchtest.
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Mi 31.03.10 15:41 
oder in einer Funktion packen wenns immer nur die 3 sind ôo.
MoveLabels(10);
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mi 31.03.10 17:28 
Genauer gesagt programmiere ich grad ein kl. Spiel, wo per Timer jede 3 Sekunden ein Label dynamisch erstellt wird. Und jedes Label soll sich dann nach unten bewegen (LabelX.Top+5 z.B.). Aber wenn ich dem Label einen Namen gebe, kommt logischerweise nach 3 Sek. die Fehlermeldung, dass ein Label mit diesem Namen bereits existiert. Wenn ich dem MyLabel nun keinen Namen gebe, dann funktioniert das auch, aber jetzt fehlt mir der Name des Labels, das sich bewegen soll, für den Befehl.
JonS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 43

XP, Vista, Seven, Ubuntu
Delphi for Win32, Delphi Prism, C#, Java, PHP, VB
BeitragVerfasst: Mi 31.03.10 17:34 
Nimm doch einfach eine Laufvariable, die sich nach jedem erstellen Label um 1 erhöht. Dann kannst du ganz einfach den Namen so erstellen :)

wfg Jon S.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 31.03.10 17:44 
Wenn du die Labels eh schon dynamisch erzeugst, kann du die Instanzen auch einfach in einem Array of TLabel speichern. Dann brauchst du FindComponent gar nicht, sondern läufst mit einer Schleife über alle Array-Einträge.

_________________
PROGRAMMER: A device for converting coffee into software.
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mi 31.03.10 18:00 
user profile iconJonS hat folgendes geschrieben Zum zitierten Posting springen:
Nimm doch einfach eine Laufvariable, die sich nach jedem erstellen Label um 1 erhöht. Dann kannst du ganz einfach den Namen so erstellen :)

wfg Jon S.


So war auch meine Idee, aber ich wusste nicht wie das genau geht, habs jetz so gemacht:
Bestimmt extrem umständlich, aber egal^^.

ausblenden 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:
var
  LabelName: Record
    Number: Integer;
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  LabelName.Number := 1;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
//_____Label.Create_____
  MyLabel := TLabel.Create(self); //MyLabel.Show;
  with MyLabel do begin
    Name := 'Label'+IntToStr(LabelName.Number);
    AutoSize := False;
    Left := RandomRange(10,770);
    Top := 50;
    Width := 20;
    Height := 20;
    Visible := True;
    Parent := Form1;
    Show;
    Color:= clBlack;
  end;
//_____Label+1_____  
  LabelName.Number := LabelName.Number+1;
end;
>M@steR<
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 288
Erhaltene Danke: 3



BeitragVerfasst: Mi 31.03.10 18:13 
Gelöscht


Zuletzt bearbeitet von >M@steR< am Di 17.09.13 02:37, insgesamt 1-mal bearbeitet
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mi 31.03.10 18:33 
Hab mal ein bisschen in der Delphi Help gestöbert und bin auf was gestoßen und habs so umgeschrieben:

ausblenden 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:
procedure TForm1.Button1Click(Sender: TObject);
begin
  for i := 1 to 10 do
  begin
    TLabel.Create(Self).Name := NamePrefix + IntToStr(i);
    with TLabel(FindComponent(NamePrefix + IntToStr(i))) do
    begin
      AutoSize := False;
      Left := RandomRange(10,770);
      Top := 50;
      Width := 20;
      Height := 20;
      Visible := True;
      Parent := Form1;
      Color:= clBlack;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  for i := 1 to LabelName.Number do
    (findcomponent('Label' + inttostr(i)) as TLabel).Top := //...
end;


Und beim 2. Button sollen sich jeweils alle Labels um 10 nach unten verschieben, aber wie mach ich das?
Ich probier ganze Zeit rum, aber dauernt crashed die .exe...
>M@steR<
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 288
Erhaltene Danke: 3



BeitragVerfasst: Mi 31.03.10 19:08 
Gelöscht


Zuletzt bearbeitet von >M@steR< am Di 17.09.13 02:37, insgesamt 1-mal bearbeitet
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mi 31.03.10 19:45 
user profile icon>M@steR< hat folgendes geschrieben Zum zitierten Posting springen:
Ömmm das "//..." hinter dem ":=" soll heißen das da noch was fehlt!

EDIT:
Zudem entspricht der untere Quellcode ja nicht mehr dem den du oben gepostet hast.
Du must dich entscheiden, willst du immer nur 10 labels erzeugen oder verschieden viele?


Verschieden viele...
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 31.03.10 20:53 
Ich glaub, mein Post ist unter gegangen.

_________________
PROGRAMMER: A device for converting coffee into software.
>M@steR<
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 288
Erhaltene Danke: 3



BeitragVerfasst: Mi 31.03.10 22:18 
Gelöscht