Autor Beitrag
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mo 20.09.04 16:16 
Ich habe folgende Frage:
Ist es möglich während der Laufzeit durch Klick eines Buttons, z.B. ein neues Label zu erstellen und diesem eine Prozedur zuzuweisen ??
OlliWausD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Mo 20.09.04 16:22 
jo geht. Hier der Code

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var neuesLabel:Tlabel;
begin
  neuesLabel := Tlabel.create(nil);
  neuesLabel.Parent := self;
  neuesLabel.Caption := 'Test';
  neuesLabel.left := 40;
  neuesLabel.top := 40;
  neuesLabel.Height := 20;
  neuesLabel.Width := 100;
  neuesLabel.Visible := true;
  neuesLabel.OnClick := Ichklickdich;
end;


mfg

OlliW

ps: Der Code lässt sich nicht als Delphi-Code dastellen. Bitte bei gelegenheit ausbessern

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.

_________________
Take it easy
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mo 20.09.04 16:39 
OlliWausD hat folgendes geschrieben:

neuesLabel.OnClick := Ichklickdich;


Könnte man das so machen das Ichklickdich ein String ist ?
Dass man z.B. schreiben kann:
neuesLabel1.OnClick :='neueslabel'+inttostr(irgendein Integer der die 1 angibt).Caption:='Hallo';
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mo 20.09.04 17:13 
du weißt schon dass er dort eine prozedur haben will und nicht deren text oder? also globale prozedur erstellen jedem label die selbe zuweisen und dann Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Mo 20.09.04 17:20 
Hallo Tobias,

mit 'neuesLabel.OnClick = IchKlickDich' wird dem neuen Label die Ereignisbehandlungsroutine 'IchKlickDich' zugewiesen. Diese Routine muss gesondert definiert werden und wird ausgeführt, wenn der Anwender das Label, welches dort zur Laufzeit erzeugt wurde anklickt. Das könnte z.B. so aussehen:

... zuerst die Deklaration ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
public
  { Public-Deklarationen }
  procedure IchKlickDich(Sender : TObject);
end;


... und dann die Ereignisbehandlungsroutine ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  
procedure TForm1.IchKlickDich(Sender : TObject);
begin
  ShowMessage('Hey, lass das bitte!!');
end;


In dem Beispiel von Olli wird dem neuen Label in Zeile 6 des Beispiels die Caption 'Test' zugewiesen.

Gruß
Gregor

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 20.09.04 17:21 
OlliWausD hat folgendes geschrieben:
ps: Der Code lässt sich nicht als Delphi-Code dastellen. Bitte bei gelegenheit ausbessern
Man muss schon Delphi-Tags drum herum machen ... :roll:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mo 20.09.04 17:47 
Wie kann ich dieses Label jetzt während der Laufzeit ansprechen z.B NeuesLabel.Caption:='Hi';
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mo 20.09.04 18:20 
Meine Wenigkeit hat folgendes geschrieben:
und dann Suche in: Delphi-Forum, Delphi-Library FINDCOMPONENT
oder ein Array of TLabel

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
OlliWausD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Di 21.09.04 08:53 
Christian S. hat folgendes geschrieben:
OlliWausD hat folgendes geschrieben:
ps: Der Code lässt sich nicht als Delphi-Code dastellen. Bitte bei gelegenheit ausbessern
Man muss schon Delphi-Tags drum herum machen ... :roll:


des is mir schon bekannt, aber der "Knopf" (schönes Wort :) ) ging nicht.
Weder bei selectierung der Zeilen, noch ohne.

Najagut. Is egal. jetzt funktionierts wieder

ausblenden Delphi-Quelltext
1:
2:
3:
4:
dfsdfasdfa
sdf
asdf
sadfasdf


mfg

OlliW

_________________
Take it easy
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Di 21.09.04 19:40 
Wie geht das mit Array of Tlabel??

kann ich dann schreiben: label[1].caption:='Hallo';

Das wäre super wenn das geht!
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Di 21.09.04 19:52 
eigentlich schon

wenn du zum Beispiel 5 Labels hast, kannst dula: array[1..5]of Tlabel;schreiben, im create oder so musst du die labels dann noch createn und im close( oder destroy) freigeben (free). Zur Laufzeit kannst du dann so, wie du geschrieben hast drauf zugreifen.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Di 21.09.04 20:04 
Vielen Dank!!
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mi 22.09.04 13:57 
Und wie kann ich dieses Array-Label dann während der Laufzeit wieder löschen? :?!?:
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Mi 22.09.04 14:13 
Antwort steht doch schon oben: Mit Free. Oder wo hängts?

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 22.09.04 14:13 
Hallo!

Mit .Free!

Gruß
Tino
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Mi 22.09.04 15:36 
Dankeschön
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 22.09.04 15:40 
mit fällt grad ein, dass ich FIndComponent geschrieben hab, ist natürlich witzlos. kann man ja auch über den Sender machen.

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Sa 25.09.04 10:55 
Wie kann ich von Form1 ein Label auf Form2 erstellen??

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
Lossy eX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1048
Erhaltene Danke: 4



BeitragVerfasst: Sa 25.09.04 11:02 
Normal erstellst du es so.
ausblenden Delphi-Quelltext
1:
2:
  neuesLabel := Tlabel.create(nil);
  neuesLabel.Parent := self;


Wenn du es auf Form2 erstellen möchtest, dann musst das Parent in diesem Falle Form1 (Also Self) wieder spiegelt durch ein Form2 ersetzen. Natürlich muss das Form2 dann in dem Formular bekannt sein. Das wars dann auch schon.

PS: Wenn du eine Owner im Create angegeben hättest, dann müsstest du diesen natürlich auch ersetzen.

_________________
Nur die Menschheit ist arrogant genug, um zu glauben sie sei die einzige intelligente Lebensform im All. Wo nicht mal das nachhaltig bewiesen wurde.
Tobias1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Sa 25.09.04 11:08 
Das geht jetzt!

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)