Autor Beitrag
V!P3R
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 13:51 
Hi
wie kann man per ButtonClick beliebig viel Shapes erstellen?
die Koordninaten sind immer die gleichen.

ausblenden Delphi-Quelltext
1:
2:
Top:20
Left:20

per buttonclick ensteht hier ein neuer Shape, beliebig oft wiederholbar

Und wie kann ich dieses shape dann markieren,
um es zu verschieben, oder geht das nur idem ich zwei EditFelder erstelle, in die man dann die Top und Leftwerte eingebe
aber auch beim eingeben bleibt die frage: wie kann ich es markieren?

MfG
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 01.12.07 13:59 
Wie meinst du "Markieren"? Du willst das Shape ansprechen? Dann gib den Shapes doch Namen, wie Shape1 usw. Dann kannst du sie gut ansprechen.
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 14:08 
nein, ich meine folgendes:

1. Ich will das ganze natürlich AUSERHALB von delphi machen in meinem fertigen programm.
2. soll man es (z.B. wie man in Word ein Bild markiert) auswählen, damit mein programm weis an welchem der shapes es was ändern soll.

am besten wär das natürlich wie in delphi, sprich man kann die größe des shapes ändern, und die Position.

MfG
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 01.12.07 14:13 
Dann würde ich dir folgendes empfehlen: Gib jedem Shape einen Tag und einen Name, der sich aus Präfix und Tag zusammensetzt. Dann deklarierst du eine OnClick procedure, die du jedem Shape zuweist. Dann Castest du den Sender, der Clickprocedure und schon weist du, welche Shape angeklickt wurde.
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 14:16 
ähmmm...vielen dank erstmal, aber ich mss gestehen, das ich das nicht ganz verstehe.

Und: wie geht das jetzt, dass man beliebig viele erstellen kann?
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 01.12.07 14:35 
Achtung: die nachfolgenden Quelltexte sind nicht geprüft!
OK. ich versuchs mal anders:
Mehrere erstellen:
ausblenden Erstellen mehrere Panels
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
i:Integer;
myPanel:TPanel;
begin
For i:=0 to {Deine Zahl} do
begin
  myPanel:=TPanel.Create(Form1);
  myPanel.Name:='Praefix'+IntToStr(i); //Unterscheidung
  myPanel.Parent:=Form1; //Auf Form 1
  myPanel.Widht 
  {.. heigth, left, top color etc.}
  myPanel.Tag:=i; //Dient zur unterscheidung
  mypanel.OnClick:=ShapeClicker(Sender: TObject);
  mypanel.Show;
  mypanel.Free;
end;

ausblenden ShapeClicprozedur
1:
2:
3:
4:
procedure TForm1.ShapeClicker(Sender: TObject);
begin
  ShowMessage('Es wurde Shape'+ IntToStr((Sender as TShape).Tag)+ 'ausgewählt.'; //Überprüft die Eigenschaft Tag
end;

Den Tag kannst du zum Beispiel einer globalen Variable zuweisen und dann kannst du damit weiterarbeiten:
ausblenden Shape n ändern
1:
TShape(FindComponent('Praefix'+IntToStr(aktuellesshape))).Color:=clRed;					
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 14:44 
Delphi findet folgende Fehler:
ausblenden Delphi-Quelltext
1:
mypanel.OnClick:=ShapeClicker(Sender: TObject);					


ausblenden Delphi-Quelltext
1:
2:
3:
[Fehler] Unit1.pas(47): Undefinierter Bezeichner: 'ShapeClicker'
//und
[Fehler] Unit1.pas(47): ':=' erwartet, aber ':' gefunden

wie behebe ich diese Fehler?

Oder besser: was ist denn: TForm1.ShapeClicker?
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 01.12.07 14:56 
ShapeClicker ist eine Prozedure, die du selber deklarieren musst. und es muss so heißen:
ausblenden Delphi-Quelltext
1:
mypanel.OnClick:=ShapeClicker;					
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 15:01 
user profile iconRegan hat folgendes geschrieben:
ShapeClicker ist eine Prozedure, die du selber deklarieren musst. und es muss so heißen:
ausblenden Delphi-Quelltext
1:
mypanel.OnClick:=ShapeClicker;					


sorry, aber delphi sagt immer noch folgendes:

ausblenden Delphi-Quelltext
1:
[Fehler] Unit1.pas(105): Undefinierter Bezeichner: 'ShapeClicker'					


oder meinst du 'ShapeClick'
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 01.12.07 15:13 
Nein. Das ist der Name der Prozedur, die aufgerufen wird. Die solltest du doch extra deklariern:
user profile iconRegan hat folgendes geschrieben:
Achtung: die nachfolgenden Quelltexte sind nicht geprüft!
ausblenden ShapeClicprozedur
1:
2:
3:
4:
procedure TForm1.ShapeClicker(Sender: TObject);
begin
  ShowMessage('Es wurde Shape'+ IntToStr((Sender as TShape).Tag)+ 'ausgewählt.'; //Überprüft die Eigenschaft Tag
end;
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 15:20 
ja, hab ich mir auch schon gedacht, aber warum is das dann unbekannt??

rapidshare.com/files/73580577/oje.rar

hier ist das "Programm"

will dir bestimmt nix aufdrängen, aber der ordner heist nicht umsonst "oje"
wenn du zeit/langweile hast, kannstes dir ja mal angucken.

PS:Ich hab Delphi 7

PPS: es scheint auf den ersten blick warscheinlcih ziemlich wirr aus, aber das wollte ich alles noch ändern.


Zuletzt bearbeitet von V!P3R am Sa 01.12.07 17:36, insgesamt 1-mal bearbeitet
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Sa 01.12.07 15:33 
user profile iconRegan hat folgendes geschrieben:

ausblenden Erstellen mehrere Panels
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
var
i:Integer;
myPanel:TPanel;
begin
For i:=0 to {Deine Zahl} do
begin
  myPanel:=TPanel.Create(Form1);
  myPanel.Name:='Praefix'+IntToStr(i); //Unterscheidung
  myPanel.Parent:=Form1; //Auf Form 1
  myPanel.Widht 
  {.. heigth, left, top color etc.}
  myPanel.Tag:=i; //Dient zur unterscheidung
  mypanel.OnClick:=ShapeClicker(Sender: TObject);
  mypanel.Show;
  mypanel.Free;
end;


Ist das absicht das du das Panel wieder freigiebst? Dadurch wird es wieder gelöscht...
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 15:56 
nein
geändet
aber wie sagt man das i immer +1 sein soll, weil bei 2 klicks auf den button sagt delphi, das es "...0" schon gibt.
ich wioll einstellen das er i per klick immer +1 nimmt.
wie gehts das?
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Sa 01.12.07 16:13 
Inc(I); oder I := I +1;
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 17:19 
ja das hab ich auch gedacht, aber das geht nicht, wenn mans in die schleife packt sagt delphi:

ausblenden Delphi-Quelltext
1:
[Fehler] Unit1.pas(108): Anweisung für FOR-Schleifenvariablen 'i'					

und wenn mans hinter oder for die schleife packt sagt delphi

ausblenden Delphi-Quelltext
1:
[Hinweis] Unit1.pas(119): Auf 'i' zugewiesener Wert wird niemals benutzt					

das project startet zwar, aber beim 2 click schmiert Projekt1 wieder ab.


warum? und wie kann man das ändern?
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Sa 01.12.07 17:21 
Poste bitte mal deinen aktuellen Quellcode.
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 17:25 
so hier ist nochmal das prog und die delphi datei zum downloaden:
rapidshare.com/files/73580577/oje.rar

und hier ist mein kompletter aktueller code:

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Shape1: TShape;
    MainMenu1: TMainMenu;
    Panel1: TPanel;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    ComboBox4: TComboBox;
    CB_Form: TComboBox;
    B_AddShape: TButton;
    Panel2: TPanel;
    Shape: TButton;
    procedure B_AddShapeClick(Sender: TObject);
    procedure ShapeClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.B_AddShapeClick(Sender: TObject);
var
i:Integer;
myPanel:TPanel;
begin
i:=i+1;
For i:=0 to 100 do
begin
  myPanel:=TPanel.Create(Form1);
  myPanel.Name:='Praefix'+IntToStr(i);
  myPanel.Parent:=Form1;
  myPanel.Width:=100;
  myPanel.Height:=100;
  myPanel.Left:=140;
  myPanel.Top:=65;
  myPanel.Color:=clRed;
  myPanel.Tag:=i;
  mypanel.OnClick:=ShapeClick;
  mypanel.Show;
end;
end;
procedure TForm1.ShapeClick(Sender: TObject);
begin
ShowMessage('Es wurde Shape'+ IntToStr((Sender as TShape).Tag)+ 'ausgewählt.');
end;

end.


MfG
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Sa 01.12.07 17:37 
LOL, jetzt hab ich erst gemerkt.

Wenn man 1x auf den Button Klick werden 100 Panels erstellt.
Wenn du nun das 2x auf den Button Klickst will er weiter 100 Panels mit dem selben Namen erstellen,
da gibt es meiner meinung 2 möglichkeiten:

ausblenden volle Höhe Die 100 Panels nochmal erstellen
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:
var
  Created: Boolean = False; //Created muss Global Dekläriert werden
  Form1: TForm;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender as TObject);
var
  I: Integer;
  myPanel:TPanel;
begin
  if (Created) then
  begin
    for I := 0 to 100 do (FindComponent('Praefix'+IntToStr(I)).Free);
    Created := False;
  end
  else begin
    for I := 0 to 100 do
    begin
      myPanel:=TPanel.Create(Form1);
      myPanel.Name:='Praefix'+IntToStr(i);
      myPanel.Parent:=Form1;
      myPanel.Width:=40;
      myPanel.Height:=40;
      myPanel.Left:=100;
      myPanel.Top:=100;
      myPanel.Color:=clRed;
      myPanel.Tag:=i;
      mypanel.Show;
      if (I = 100) then Created := True
      else Created := False;
    end;
  end;
end;


ausblenden Weitere 100 Panels erstellen
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:
var
  Last: Integer = 0; //Last muss Global Dekläriert werden
  Form1: TForm;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender as TObject);
var
  I: Integer;
  myPanel:TPanel;
begin
  for I := Last to (Last + 100) do
  begin
    myPanel:=TPanel.Create(Form1);
    myPanel.Name:='Praefix'+IntToStr(i);
    myPanel.Parent:=Form1;
    myPanel.Width:=40;
    myPanel.Height:=40;
    myPanel.Left:=100;
    myPanel.Top:=100;
    myPanel.Color:=clRed;
    myPanel.Tag:=i;
    mypanel.Show;
    if (Last = (Last + 100)) then Last := Last + 200;
  end;  
end;
V!P3R Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 151



BeitragVerfasst: Sa 01.12.07 17:40 
ich will per klick aber nur ein shape erstellen.

UND: wie kann ich jetzt den shape markieren??
.#R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

Windows XP Prof.
CodeGear Delphi 2007
BeitragVerfasst: Sa 01.12.07 17:47 
Oben hast du geschrieben du willst mehrere Shapes erstellen :!:

P.S: Erstelle bitte ein Separates Thread, für eine neue Frage.