Einzelnen Beitrag anzeigen

OSIcreate

Registriert seit: 25. Mär 2008
16 Beiträge
 
#1

Kontrolle über Unterklasse OnClick Ereigniss

  Alt 9. Apr 2008, 08:41
Moin

Ich hab da ma ne Frage und zwar wie kann ein Objekt in meim Fall ein TPanel in der Klasse TLangSwitcher feststellen das Objekte die auf im liegen angeklickt werden in meinem Fall ebenfalls ein Panel in der Klasse (TItems)

Erklärung zum Quellcode ich hab ne GrundKlasse TLangSwitcher ein Panel auf dem liegen mehere Objekte der Klasse TItems die aus einem Grundpanel zwei Labels und einer Checkbox besteht Panels

Das Problem ist dass immer nur ein Objekt von TItem makiert sein darf. Aber um die Makierung aufheben zu können muss meine Grundklasse TLangSwitcher mitkriegen wenn das OnClickereigniss der TItemklasse ausgelöst wird.


hier mein quellcode:


Delphi-Quellcode:
unit USwitcher;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls,IniFiles, ULanguage, CheckLst;

type
  TItems = class
  private
  public
    panb : TPanel;
    chk : TCheckBox;
    lbl : TLabel;
    text : TLabel;
    constructor create(pan : TPanel; Y : integer; Capt,txt : string; che : boolean);
    procedure itemOnClick(Sender : TObject);
  end;


  TLangSwitcher = class(TPanel)
  private
    items : TListBox;
    itList : Tlist;
  public
    procedure setitems(ID : string);
    procedure createList;
    function getList : TListBox;
  end;


implementation


//******************************************************************************
// Items
constructor TItems.create(pan : TPanel; Y : integer; Capt,txt : string; che : boolean);
begin
  panb := TPanel.create(pan);
  with panb do
  begin
    Parent := pan;
    Top := Y;
    Left := 0;
    Height := 15;
    Width := pan.Width-1;
    BorderStyle := bsNone;
    Color := clWhite;
    OnClick := itemOnClick;
    if che = true then Color := clBackground;
  end;


  chk := TCheckBox.Create(panb);
  with chk do
  begin
    parent := panb;
    Height := 9;
    Width := 9;
    Left := 2;
    Top := 2;
    Caption := '';
    Font.Color := clBackground;
    Font.Size := 8;
    Checked := che;
    if che = true then Color := clBackground;
    OnClick := itemOnClick;
  end;

  lbl := TLabel.Create(panb);
  with lbl do
  begin
    parent := panb;
    Height := 12;
    Width := 12;
    Top := 0;
    Left := 15;
    AutoSize := false;
    Alignment := taCenter;
    Color := clBlack;
    Font.Color := clBackground;
    Font.Name := 'Arial';
    Font.Size := 6;
    Caption := capt;
    OnClick := itemOnClick;
  end;

  text := TLabel.Create(panb);
  with text do
  begin
    parent := panb;
    Height := 15;
    Top := 0;
    Left := 27;
    Width := pan.Width-Left;
    AutoSize := false;
    Font.Color := clBlack;
    Font.Name := 'Arial';
    Font.Size := 8;
    Caption := txt;
    OnClick := itemOnClick;
  end;

end;


procedure TItems.itemOnClick(Sender : TObject);
begin
  if panb.Color = clBackground then
  begin
   chk.Color := clWhite;
   chk.Checked := false;
   panb.Color := clWhite;
  end
  else
  begin
    chk.Color := clBackground;
    chk.Checked := true;
    panb.Color := clBackground;
  end;
end;

//******************************************************************************




//******************************************************************************
// Switcher
procedure TLangSwitcher.createList;
begin
  items := TListBox.Create(self);
  items.Parent := self;
  items.Visible := false;

  itList := TList.Create;
end;

procedure TLangSwitcher.setitems(ID : string);
var i,posy : integer;
begin
  posy := 1;
  for i := 0 to items.Items.Count-1 do
  begin
    if copy(items.Items[i],1,2) = ID then itList.Add(TItems.Create(self,posy,copy(items.Items[i],1,2),copy(items.Items[i],3,Length(items.Items[i])),true))
    else itList.Add(TItems.Create(self,posy,copy(items.Items[i],1,2),copy(items.Items[i],3,Length(items.Items[i])),false));
    Height := Height + 14;
    Top := Top - 14;
    posy := posy + 14;
  end;

  self.Height := self.Height + 4;
end;

//---------------------- Getter ------------------------------------------------
function TLangSwitcher.getList : TListBox;
begin
  result := items;
end;

//******************************************************************************






end.

Bedanke mich jetzt schon für eure Antworten

mfg
  Mit Zitat antworten Zitat