Autor Beitrag
r_le
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Sa 22.05.04 19:12 
Hallo!

Folgendes Problem:
Ich hab ne neue Komponente erstellt, abgeleitet von TLabel. Beim Klick darauf wird zusätzlich eine ListBox erstellt, und wenn man in der auf ein Element klickt soll diese wieder geschlossen werden.

Hier mal so grob der Code dazu:

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:
24:
25:
26:
27:
28:
const
  WM_ListBoxFree=WM_USER+1;

type
  TMyLabel=class(TLabel)
  private
    ListBox: TListBox;
    procedure LabelClick(Sender: TObject);
    procedure ListBoxClick(Sender: TObject);
    procedure MsgHandler(var Msg: TMessage); message WM_ListBoxFree;
  end;

procedure TMyLabel.LabelClick(Sender: TObject);
begin
  ListBox:=TListBox.Create(self);
  ListBox.OnClick:=ListBoxClick;
end;

procedure TMyLabel.ListBoxClick(Sender: TObject);
begin
  {...}
  PostMessage(ListBox.Handle,WM_ListBoxFree,0,0);
end;

procedure TMyLabel.MsgHandler(var Msg: TMessage);
begin
  ListBox.Free;
end;


So wie es jetzt ist wird aber der MsgHandler gar nicht aufgerufen und somit die ListBox auch nicht entfernt. Ich hab schon ein bißchen mit den Parametern von PostMessage rumgespielt, aber ich krieg es einfach nicht hin.


Zuletzt bearbeitet von r_le am Sa 22.05.04 19:22, insgesamt 1-mal bearbeitet
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Sa 22.05.04 19:21 
Kann dir dabei leider nicht helfen.

Bist du denn sicher, dass es nicht auch eine normale TComboBox tut?
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 22.05.04 19:23 
1. auf welche listboxitems willst du klicken? laut obigem source sind keine da!
2. musst du dem listbox.onClick event die methode "TMyLabel.ListBox1Click" zuweisen:
ausblenden Delphi-Quelltext
1:
ListBox.OnClick := ListBox1Click;					

3. wenn ein zweites (drittes, viertes,...) mal auf das Label anstatt den Items geklickt wird, wird die listbox ein zweites mal created...

raziel

_________________
JSXGraph
r_le Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Sa 22.05.04 19:24 
Gehen würde das schon, aber aus Übersichtlichkeitsgründen macht sich das mit nem unscheinbaren Label an der Stelle einfach besser.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 22.05.04 19:26 
tipp: popupmenu?

_________________
JSXGraph
r_le Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Sa 22.05.04 19:26 
@raziel

Ja, das mit dem OnClick-Event ist mir auch gerade aufgefallen. Hatte ich aber nur in dem Kurz-Code oben vergessen, im richtigen Programm ist's da.

Das mit dem mehrfachen erstellen ist ein guter Tipp, daran hatte ich noch gar nicht gedacht. :)
r_le Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mo 24.05.04 09:58 
Hat noch jemand nen Tip für mein ursprüngliches Problem (den PostMessage-Aufruf)?
Das hab ich nämlich immer noch nicht hingekriegt. :(
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mo 24.05.04 17:17 
ja: immer noch PopUpMenu. Is doch viel einfacher als ne ListBox!
Bei OnClick normales Label (oder onmouseup) einfach das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var tmppt: TPoint;
begin
  tmppt.X := Label1.Left;
  tmppt.Y := Label1.Top + Label1.Height;
  tmppt := ClientToScreen(tmppt);
  popupmenu1.Popup(tmppt.X, tmppt.Y);
end;


dann popt das popupmenu genau an der linken unteren kante des labels auf und fertich. brauchst dir keine weiteren gedanken machen.

raziel

_________________
JSXGraph
r_le Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: Mo 24.05.04 17:35 
Ich dachte in einem PopUpMenu kann man nicht scrollen. Und da ich viele Elemente hatte wollte ich das nicht nehmen. Hab mich aber gerade vom Gegenteil überzeugt. :-)

Ich hab für die ListBox inzwischen ne eigene Klasse erstellt, direkt abgeleitet von TListBox. Damit klappt dann das entfernen mittels PostMessage-Aufruf.

Mal sehen, wenn noch Zeit ist änder ich es noch in ein PopUpMenu.

Danke für die Hilfe!