Autor Beitrag
DXC
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 06.08.05 12:22 
Hi,

weiß jemand vielleicht wie ich es machen kann dass wenn ich auf einen Button kilcke dass dann automatisch ein label erstellt wird (nicht mit visible, etc.!) mit der position xxxxx ?

MFG
DXC
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 12:31 
Du willst also eine Komponente zur Laufzeit erstellen. Schau dir mal folgenden Code an:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.Button1Click(Sender: TObject);
var
MyLabel: TLabel;
begin
MyLabel := TLabel.Create(Form1);
MyLabel.Caption := 'Mein eigenenes Label.';
MyLabel.Top := 100;
MyLabel.Left := 150;
MyLabel.Parent := Form1;
end;


;)
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 06.08.05 12:37 
Eventuell ist das mit einem with do noch etwas schöner ;)

AXMD
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 12:41 
user profile iconAXMD hat folgendes geschrieben:
Eventuell ist das mit einem with do noch etwas schöner ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var
MyLabel: TLabel;
begin
with MyLabel do
  begin
  Create(Form1);
  Caption := 'Mein eigenenes Label.';
  Top := 100;
  Left := 150;
  Parent := Form1;
  end;
end;

Bitte sehr... :tongue:
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 06.08.05 12:44 
Wenn ich mich nicht täusche, sollte das eine AV zur Folge haben. Da du MyLabel.Create aufrufst, obwohl das Label noch nicht erzeugt ist. Es muss ja MyLabel := TLabel.Create... heißen ;)

AXMD
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 12:49 
Überarbeitete Fassung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var
MyLabel: TLabel;
begin
MyLabel := TLabel.Create(Form1);
with MyLabel do
  begin
  Caption := 'Mein eigenenes Label.';
  Top := 100;
  Left := 150;
  Parent := Form1;
  end;
end;


:motz: :mrgreen:

Aber die Fehlermeldung war "A component named Button1 already exists."... :tongue: Keine AV... Was sagst du dazu, AXMD?
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 13:02 
user profile iconWeBsPaCe hat folgendes geschrieben:
Überarbeitete Fassung:



:motz: :mrgreen:

Aber die Fehlermeldung war "A component named Button1 already exists."... :tongue: Keine AV... Was sagst du dazu, AXMD?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Button1Click(Sender: TObject);
var x,y,breite:integer;//Position des Labels
MyLabel: TLabel;
begin
MyLabel := TLabel.Create(Form1);//das Label muss ja erstma erzeugt werden^^
with MyLabel do
  begin
  Caption := 'Mein eigenenes Label.';
  Top := y;
  Left := x;
  width:=breite;//oder autosize:=true;
  Parent := Form1;//dat dingen soll ja auf Form1 erscheinen....n bissl OOP
  end;
end;

Jojo Webby...so ein großer Fehler, das dingen nit zu createn^^ :-P
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 13:05 
user profile iconKroni hat folgendes geschrieben:
Jojo Webby...so ein großer Fehler, das dingen nit zu createn^^ :-P

Wo hab ich's denn nicht created? :gruebel: Ich blick' deinen Code ehrlichgesagt nicht so ganz... Wo ist denn der Unterschied zu meinem?
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 13:07 
Na, das ist einfach nur dein Code mit ein paar anderen Einstellungen, die man nochmal machen sollte.....
Zb.: Die Breite einstellen oder zumindest AutoSize auf true setzen.
Was bringt es dir, wenn du n label hast, das aber quasi kein width hat^^ lol!
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 13:10 
user profile iconKroni hat folgendes geschrieben:
Na, das ist einfach nur dein Code mit ein paar anderen Einstellungen, die man nochmal machen sollte..... Zb.: Die Breite einstellen oder zumindest AutoSize auf true setzen. Was bringt es dir, wenn du n label hast, das aber quasi kein width hat^^ lol!

Bei TLabel ist Autosize standartmäßig auf True. ;)

Guckst du mal das hier an:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
function NewLabel(LblForm: TForm; LblCaption: TCaption; LblTop: Integer; LblLeft: Integer): TLabel;
begin
Result := TLabel.Create(LblForm);
with Result do
  begin
  Caption := LblCaption;
  Top := LblTop;
  Left := LblLeft;
  Parent := LblForm;
  end;
end;


Aufruf z.B. so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);
var
MyLabel: TLabel;
begin
MyLabel := NewLabel(Form1, 'Mein eigenes Label'100100);
end;


:mrgreen:
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 13:12 
Na, das lohnt sich aber nur, wenn du oft n neuese Label machen willst, denn nur IDIOTEN (O-Ton mienes Lehreres) schreiben zwiemal den selben oder ähnlichen Source..

Und was ich noch gelernt habe, bzw meine eigene Sache ist:

Ich vertraue nie vorgegebene werte......z.B. dass AutoSize auf True ist....lieber selber setzten, dann kannst du dir auch sicher sein =)
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 13:15 
user profile iconKroni hat folgendes geschrieben:
Na, das lohnt sich aber nur, wenn du oft n neuese Label machen willst, denn nur IDIOTEN (O-Ton mienes Lehreres) schreiben zwiemal den selben oder ähnlichen Source..

Na, da wird sich user profile iconDXC aber freuen, dass er ein Idiot ist. :mrgreen: Wieso soll man da ein Idiot sein?! :gruebel:

user profile iconKroni hat folgendes geschrieben:
Ich vertraue nie vorgegebene werte......z.B. dass AutoSize auf True ist....lieber selber setzten, dann kannst du dir auch sicher sein =)

Höhö... Und was sagt dein Lehrer dazu? Oder schmeißt er dich gleich raus? :mrgreen:
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 13:18 
Stop....
Das war nit an user profile iconDXC gerichtet!
Das war nur ein O-Ton von meinem Lehrer, der UNS als Idioten bezeichnet, wenn wir zweimal den ähnlichen Soruce schreiben.
Wenn ich das nur einmal brauche, wie user profile iconDXC in diseem Beispiel, ist er selbtredend kein Idiot!

Nun ja......
Zitat:
Kroni hat folgendes geschrieben:
Ich vertraue nie vorgegebene werte......z.B. dass AutoSize auf True ist....lieber selber setzten, dann kannst du dir auch sicher sein =)

Höhö... Und was sagt dein Lehrer dazu? Oder schmeißt er dich gleich raus? :mrgreen:


Selbstredend nicht, aber es ist meine Meinung, die auch mein Lehrer teilt^^ :-P
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 13:23 
Ich glaube, wir werden grad ein bisschen OffTopic. :tongue: Wir machen das in ICQ zu Ende...user defined image

Ist doch selbstredend... :mrgreen:
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 13:24 
Aber vielleicht möchten ja noch andere Leute wissen, wie man gut programmiert^^

Ok.....deine ICQ nummer habe ich....LETS FIGHT WeBsPaCe ^^

Hoffe wir konnten dir helfen!
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 06.08.05 14:59 
Ähem Aäh was wollt ich schnell wieder?... Ahhh :: Danke

Zitat:

Ok.....deine ICQ nummer habe ich....LETS FIGHT WeBsPaCe ^^


Hack am besten seinen Webspace ^^, ne Spaß :wink:

thxle
mfg
DXC
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 15:02 
So, aber jetzt will ich dann doch mal wissen, welche Methode du verwendest. ;)
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 06.08.05 15:06 
WeBsPaCe?
Ich verwende die Methode mit dem Skalpell....oder doch lieber Messer?!? :wink:
DXC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 61

WINXP + SP2
D6 Pers, D2005 Pers
BeitragVerfasst: Sa 06.08.05 15:07 
Ich nehm einfach alle beide. Fürs erste Label nehm ich *** Webspace*** seins und schreib klein dahinter "by webspace" und bein anderen "by Kroni" :lol: :wink:

DXC

// Edit


Zuletzt bearbeitet von DXC am Sa 06.08.05 15:10, insgesamt 1-mal bearbeitet
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 06.08.05 15:07 
user profile iconKroni hat folgendes geschrieben:
WeBsPaCe?
Ich verwende die Methode mit dem Skalpell....oder doch lieber Messer?!? :wink:

:rofl: Fühl' dich doch nicht immer so angesprochen, nur weil wir verheiratet sind. :rofl: :lol:

^^Spamming... :cry:

user profile iconDXC hat folgendes geschrieben:
Ich nehm einfach alle beide. Fürs erste Label nehm ich deins und schreib klein dahinter "by webspace" und bein anderen "by Kroni" :lol: :wink:

Du nimmst wirklich Kroni's Methode? :eyes: Wie verrückt... :tongue: