Autor Beitrag
M. Raab
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 334
Erhaltene Danke: 1

WIN 7
Delphi XE
BeitragVerfasst: So 19.02.06 14:48 
Hallo

ich habe ein Problem mit folgendem Code. Der Nutzer kann bei mir mehrere Labels zur Laufzeit erzeugen. Klickt er mit der linken Maustaste ein Label ein weiteres mal an, kann er es bearbeiten. Das funktioniert auch recht gut.

Bearbeitet er aber gerade ein Label und klickt dann mit der Maus auf ein anderes Label um dieses nun zu bearbeiten, möchte ich den neuen Text des vorherigen Labels (welches gerade bearbeitet wurde) speichern. Dazu habe ich das Leave Ereignis gemacht. Das Ereignis wird jedoch nie aufgerufen - es wird nicht ausgeführt.

Kann mir da jemand helfen ?


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:
//*******************************************************************
procedure TForm11.LabelCreate(xleft,xtop,xno: integer; c: string; cc: TColor);
  begin
    BPLabel[BPEditCount]:=TLabel.Create(Form11);
    BPLabel[BPEditCount].Parent:=Form11;
    BPLabel[BPEditCount].Tag:=xno;
    BPLabel[BPEditCount].Cursor:=crHandPoint;
    BPLabel[BPEditCount].Left:=xLeft;
    BPLabel[BPEditCount].Top:=xTop;
    BPLabel[BPEditCount].Font.Name:='Arial';
    BPLabel[BPEditCount].Font.Size:=8;
    BPLabel[BPEditCount].Font.Style:=[fsBold];
    BPLabel[BPEditCount].Font.Color:=clNavy;
    BPLabel[BPEditCount].width:=length(trim(c))*6;
    BPLabel[BPEditCount].height:=15;
    BPLabel[BPEditCount].OnMouseDown:=BPLabelMouseIn;
    BPLabel[BPeditCount].OnMouseLeave:=BPLabelMouseLeave;
    BPLabel[BPEditCount].Caption:=trim(c);
    BPLabel[BPEditCount].visible:=true;
    BPLabel[BPeditCount].color:=cc;
    BPEdit.Text:='';
    BPEdit.visible:=false;
  end;
//*******************************************************************


//*******************************************************************
procedure TForm11.BPLabelMouseLeave(Sender: TObject);
begin
  BPLabel[BPedit.Tag].Visible:=true;
  BPLabel[BPedit.Tag].caption:=BPEdit.Text;
  BPEdit.visible:=false;
end;
//*******************************************************************


//*******************************************************************
procedure TForm11.BPLabelMouseIn(Sender: TObject; Button: TMouseButton;
              Shift: TShiftState; X, Y: Integer);
  begin
    BPModify:=false;


    // mit der rechten Maustaste - Label wird wieder gelöscht
    if Button=mbRight then
      begin
         if application.messagebox(PChar('Wollen Sie das Text - Feld wirklich löschen ?'+chr(13)),
                                         PChar('Löschen eines TEXT - FELDES'),MB_YESNO+MB_ICONWARNING+MB_DefButton2)=6 then
           begin
             BPLabel[(Sender as TLabel).Tag].visible:=false;
             BPEdit.Text:='';
           end;
         BPModify:=false;
      end;

    // mit der linken Maustaste - Label wird bearbeitet
    if Button=mbLeft then
      begin
        BPLabel[(Sender as TLabel).Tag].visible:=false;
        BPEdit.Left:=BPLabel[(Sender as TLabel).tag].left;
        BPEdit.Top:=BPLabel[(Sender as TLabel).tag].Top;
        BPEdit.text:=BPLabel[(Sender as TLabel).tag].Caption;
        BPEdit.Tag:=BPLabel[(Sender as TLabel).tag].tag;
        BPEdit.Width:=100;
        BPEdit.Visible:=true;
        BPModify:=true;
        BPEdit.SetFocus;
      end;

  end;
//*******************************************************************



Vielen Dank und Gruss


Markus

_________________
Das Leben besteht aus Bits und Bytes - nur: wo laufen sie denn ????
Super ... Du kannst das zwar lesen, toll..... aber: völlig zwecklos !!!
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 19.02.06 20:27 
Ich würde das so machen:
Bei onClick der Labels speicherst du den Namen des aktuellen Labels.
Bei weiterem OnClick prüfst du, ob der alte Name != der neue Name ist.
In diesem Fall "speicherst" du das Label.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)