Autor Beitrag
ak
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 240

Suse Windows 9 XP
D6 Professional
BeitragVerfasst: Sa 08.11.03 12:28 
Hallo Leute,

ich habe zur Laufzeit eine variable Anzahl von Buttons erstellt. Alle buttons haben in einer FOR-Schleife einen Namen und eine onklick prozedur zugewiesen bekommen. Die onklickprozedur ist immer die gleiche. Jetzt möchte ich in der onklickprozedur einem Label den Namen des buttons übergeben. Wie mache ich das? In der schleife hat jeder button einen anderen Namen bekommen. Hier mal die Prozedur.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm2.testprozedur(ASender: TObject);
begin
     Label.Caption:=  ??? ;
end;


Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Gruß AK
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Sa 08.11.03 12:32 
meinst du das?

ausblenden Delphi-Quelltext
1:
 TComponent(Sender).Name					
ak Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 240

Suse Windows 9 XP
D6 Professional
BeitragVerfasst: Sa 08.11.03 12:34 
Hallo,

ja das ist mal wieder typisch, kam habe ich das gepostet, klappt es auch bei mir :-).
Aber danke für den tip, genau das ist es. :-)
Es lag daran, das ich Intrawebkomponenten benutze.

ausblenden Quelltext
1:
IWLabel321.Caption:= (ASender as TIWButton32).name;					

_________________
Gruß AK
catweasel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 487
Erhaltene Danke: 1

Win 7 64bit
Delphi 7 Second Sedition V7.2
BeitragVerfasst: Sa 08.11.03 21:20 
Titel: Ähnliches Problem...
Hi,

habe ein ähnliches Problem und das mit dem

Zitat:
meinst du das?

Sourcecode:
TComponent(Sender).Name


nicht so ganz verstanden.... Ich bekomme irgendwie nicht heraus, welches Panel angeklickt wurde.

hier ist mein quellcode:
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:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    zeilen: TLabeledEdit;
    Bevel1: TBevel;
    procedure knopfpatch(anzahl,xalign,yalign,xrange: integer);
    procedure patchklick(Sender : TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.knopfpatch(anzahl,xalign,yalign,xrange: integer);
var
x,y,z : integer;
knopf : TPanel;
begin
y := yalign;
x := xalign -80;

for z := 1 to anzahl do


begin
x := x+80;
if x > xrange+xalign then
begin
x:=xalign;
y := y+80;
end;


knopf := TPanel.Create(self);
knopf.parent := self;
knopf.Width := 75;
knopf.Height := 75;
knopf.Top := y;
knopf.Left := x;
knopf.Name := 'knopf'+ inttostr(z);
knopf.OnClick := patchklick;

end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
knopfpatch(strtoint(zeilen.Text),20,20,380);
end;

procedure TForm1.patchklick(Sender: TObject);
var
paname : string;
begin
if sender = button1 then showmessage('Klick');
end;

end.

Anstelle von Button1 müsste ich dann knopf1 ..knopf2 .. etc.. durchtesten (dann eher nicht mit if..... :wink: ) aber soll erstmal überhaupt funktionieren.

Aber er sagt er kennt knopf1 und so nicht.. Klar. existiert ja auch zur Designtime noch garnicht....

und :

ausblenden Delphi-Quelltext
1:
sender.name					


geht ja auch nicht....

Wie bekomm ich raus welhces Panel geklickt wurde?

Catweasel

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Pommes werden schneller fertig wenn man sie vor dem Frittieren einige Minuten in siedendes Fett legt.
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: Sa 08.11.03 21:34 
@catweasel:

in deinem Fall würde ich über die Tag-eigenschaft gehen

z.B.:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
knopf := TPanel.Create(self);
...
knopf.OnClick := patchklick; 
knopf.tag := anzahl;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.patchklick(Sender: TObject);
begin
  case TComponent(Sender).Tag of
    1: ...
    2: ... 
end;

kommt aber auch drauf an, was du tun willst. Der Tag hat z.b. den Vorteil das du mit Case arbeiten kannst.

dein
Zitat:

procedure TForm1.patchklick(Sender: TObject);
var
paname : string;
begin
if sender = button1 then showmessage('Klick');
end;

kann nicht funktioren, da dein patchklick von einem Panel ausgelöst wird und nicht vom Button1. (knopf ist ja ein Tpanel)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.patchklick(Sender: TObject);
begin
if sender is Tpanel then showmessage(TPanel(sender).name+'wurde geklickt');
end;

oder du nimmst auch hier TComponent(sender).name

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
catweasel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 487
Erhaltene Danke: 1

Win 7 64bit
Delphi 7 Second Sedition V7.2
BeitragVerfasst: Sa 08.11.03 21:43 
Hi,

Danke für die rasche Antwort.... :D

Angetan von so prompter Hilfe.... gleich mal noch ne Frage... :wink:

Kannst du dichauch mal meiner 2 Fragen im Object-Pascal Forum annehmen
(Zu Owner/Parent)
und
( Problem mit eigner Klasse) .. das TSuprchart Ding..


speziell letzteres liegt mir sehr am Herzen. Da gehts auch um ein Panel und irgendwas ist da wohl falsch deklariert :(

Catweasel

_________________
Pommes werden schneller fertig wenn man sie vor dem Frittieren einige Minuten in siedendes Fett legt.