Autor Beitrag
MH1987
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Mi 10.01.07 10:04 
hi,

ich möchte gerne eine procedure haben, die das angeklickte element aus meinem array [1..25] of TShape in ein stCircle umwandelt.

hier was ich bisher habe:

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

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  shape: array [1..25of TShape;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
  for i:= 1 to 25 do
    begin
      shape[i]:= TShape.Create(Form1);
      shape[i].Parent:= form1;
      shape[i].Width:= 30;
      shape[i].Height:= 30;
      shape[i].Left:= ((i-1mod 5) * 30;
      shape[i].Top:= ((i-1div 5) * 30;
    end;
end;

end.
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Mi 10.01.07 10:35 
Hi!

Das ist ja noch nicht viel. ;-)


Wenn ein TShape (bin mir da gerade nicht sicher) ein OnClick-Routine hat, ist das doch kein Problem. Ansonsten neue Komponente aus TShape ableiten, die auf OnClick reagiert und Ereignis hinterlegen. Weise beim Erstellen deiner Shapes dann einfach dem Ereignis eine Prozedur zu, die genau das macht, was du willst. ;-)

Im Internet gibt es zur Komponentenerstellung zahllose Beispiele. Wenn du trotzdem noch Probleme hast, melde dich einfach.

Gruß
MH1987 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Mi 10.01.07 10:38 
mit der procedure zuweisen hat ich auch schon dran gedacht.... weiss aber nicht wie man das macht :-(

das shape hat eine onmousedown routine
mit einem einzelnen shape schaff ich es auch, mein problem ist es das in dem ganzen array zu machen
freedy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 403
Erhaltene Danke: 1

Winows 7
Delphi XE
BeitragVerfasst: Mi 10.01.07 11:08 
Denke, dass das MouseUp da besser geeignet ist.

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:
// im OnCreate
[...]
  for i:= 1 to 25 do
    begin
      shape[i]:= TShape.Create(Form1);
      shape[i].Parent:= form1;
      shape[i].Width:= 30;
      shape[i].Height:= 30;
      shape[i].Left:= ((i-1mod 5) * 30;
      shape[i].Top:= ((i-1div 5) * 30;
      shape[i].OnMouseUp := ShapeMouseUp;
    end;

[...]

procedure TForm1.ShapeMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Sender is TShape) then
  begin
    TShape(Sender).Shape := stCirle;
  end;
end;



Jetzt wird die Prozedur immer ausgelöst, wenn der Benutzer auf einem Shape die Maustaste loslässt. Wenn du sicher gehen willst, dass er sie auch auf diesem Shape gedrückt hat, müsstest du evtl. noch ein paar Abfragen setzen (z.B. im MouseDown ein Boolean setzen und im MouseUp deinen Code nur ausführen, wenn dieser Boolean auch gesetzt ist). Es besteht sonst die Möglichkeit, die Maustaste zu drücken, festzuhalten und die Maus dann über ein anderes Shape zu ziehen. Dann würde die Ereignisbehandlung dieses Shapes ausgelöst werden.
MH1987 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 98



BeitragVerfasst: Mi 10.01.07 15:01 
ok, vielen Dank!
Hat mir sehr geholfen!

Gruß
Matthias