Einzelnen Beitrag anzeigen

Alex_ITA01

Registriert seit: 22. Sep 2003
1.115 Beiträge
 
Delphi 12 Athens
 
#1

Komponenteneigenschaften ändern -> Invalidate ausführen

  Alt 5. Jan 2005, 15:02
Also ich habe folgendes Gerüst:
Ich möchte wenn ich im Objektinspektor die Eigenschaft "HeaderCount" ändere ein Update,Invalidate oder wie auch immer der ListBox aufrufen.Es würde ja reichen wenn ich den ersten Source aufrufen kann aber wie kann ich von SETTINGS auf meine Kompo zugreifen damit ich im Objektinspektor die Änderungen auch sofort sehe?
MFG Alex

Delphi-Quellcode:
  if Assigned(Settings) then
  begin
    for i := 0 to Settings.HeaderCount do
    begin
      with FHeaderControl do
      begin
        HS := Sections.Add;
        HS.Text := 'Item' + IntToStr(i);
        HS.Width := Width div Settings.HeaderCount;
      end;
    end;
    FHeaderControl.Invalidate;
  end;
Komponente:
Delphi-Quellcode:
unit HeaderListBox;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, Types, Windows, Graphics, ComCtrls;

type
  TSettings = class(TPersistent)
  private
    { Private-Deklarationen }
    FHeaderCount: Byte;
    FTextColor : TColor;
    FFrameColor : TColor;
    procedure SetHeaderCount(Value : Byte);
    procedure SetTextColor (Value : TColor);
    procedure SetFrameColor (Value : TColor);
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    Constructor create;
  published
    { Published-Deklarationen }
    property HeaderCount : Byte read FHeaderCount write SetHeaderCount default 2;
    property TextColor : TColor read FTextColor write SetTextColor default clBlack;
    property FrameColor : TColor read FFrameColor write SetFrameColor default clWhite;
  end;

  THeaderListBox = class(TListBox)
  private
    { Private-Deklarationen }
    FSettings : TSettings;
    FHeaderControl : THeaderControl;
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
    procedure CreateWnd; override;
  published
    { Published-Deklarationen }
    property Settings : TSettings read FSettings write FSettings;
  end;
{ ---------------------------------------------------------------------------- }
procedure Register;
{ ---------------------------------------------------------------------------- }
implementation
{ ---------------------------------------------------------------------------- }
procedure Register;
begin
  RegisterComponents('Test', [THeaderListBox]);
end;
{ ---------------------------------------------------------------------------- }
{ THeaderListBox }
{ ---------------------------------------------------------------------------- }
constructor THeaderListBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Self.Left := 248;
  Self.Width := 249;
  Self.Height := 185;
  Self.Top := 100;
  Self.Style := lbOwnerDrawFixed;
  Self.OnDrawItem := DrawAllItem;

  FSettings := TSettings.Create;
  
  if ComponentState = [csDesigning] then Exit;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.CreateWnd;
var
  i : Integer;
  HS: THeaderSection;
begin
  inherited;
  FHeaderControl := THeaderControl.Create(Self);
  FHeaderControl.Parent := Self.Parent;
  FHeaderControl.Align := alCustom;
  FHeaderControl.Left := 248;
  FHeaderControl.Width := 249;
  FHeaderControl.Height := 20;
  FHeaderControl.Top := 81;
  FHeaderControl.Style := hsButtons;
  FHeaderControl.Show;
  FHeaderControl.OnSectionResize := SectionResize;

  if Assigned(Settings) then
  begin
    for i := 0 to Settings.HeaderCount do
    begin
      with FHeaderControl do
      begin
        HS := Sections.Add;
        HS.Text := 'Item' + IntToStr(i);
        HS.Width := Width div Settings.HeaderCount;
      end;
    end;
    FHeaderControl.Invalidate;
  end;
end;
{ ---------------------------------------------------------------------------- }
destructor THeaderListBox.Destroy;
begin
  if Assigned(FSettings) then
    FSettings.Free;
  inherited;
end;
{ ---------------------------------------------------------------------------- }
procedure THeaderListBox.Loaded;
begin
  inherited Loaded;
  if ComponentState = [csDesigning] then Exit;
end;
{ ---------------------------------------------------------------------------- }
{ TSettings }
{ ---------------------------------------------------------------------------- }
constructor TSettings.create;
begin
  inherited Create;
  TextColor := clBlack;
  FrameColor := clWhite;
  FHeaderCount := 2;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetHeaderCount(Value: Byte);
begin
  if Value <> FHeaderCount then
  begin
    FHeaderCount := Value;
    //Invalidate; <--- Aktualisieren der ListBox!!!
  end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetFrameColor(Value: TColor);
begin
  if Value <> FFrameColor then
  begin
    FFrameColor := Value;
    //Invalidate;
  end;
end;
{ ---------------------------------------------------------------------------- }
procedure TSettings.SetTextColor(Value: TColor);
begin
  if Value <> FTextColor then
  begin
    FTextColor := Value;
    //Invalidate;
  end;
end;
{ ---------------------------------------------------------------------------- }
end.
Let's fetz sprach der Frosch und sprang in den Mixer
  Mit Zitat antworten Zitat