|
Antwort |
Registriert seit: 22. Sep 2003 1.115 Beiträge Delphi 12 Athens |
#1
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:
Komponente:
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;
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
|
Zitat |
Registriert seit: 22. Sep 2003 1.115 Beiträge Delphi 12 Athens |
#2
Habs gelöst!!!
Lösung hier:
Delphi-Quellcode:
MFG Alex
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; FOnEffectChange: TNotifyEvent; procedure SetHeaderCount(Value : Byte); procedure SetTextColor (Value : TColor); procedure SetFrameColor (Value : TColor); procedure DoChanges; 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; property OnEffectChange: TNotifyEvent read FOnEffectChange write FOnEffectChange; end; THeaderListBox = class(TListBox) private { Private-Deklarationen } FSettings : TSettings; FHeaderControl : THeaderControl; procedure UpdateChanges(Sender: TObject); 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('Jung', [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; FSettings := TSettings.Create; FSettings.OnEffectChange := UpdateChanges; if ComponentState = [csDesigning] then Exit; end; { ---------------------------------------------------------------------------- } procedure THeaderListBox.CreateWnd; begin inherited CreateWnd; 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; UpdateChanges(Self); end; { ---------------------------------------------------------------------------- } destructor THeaderListBox.Destroy; begin if Assigned(FSettings) then FSettings.Free; inherited; end; { ---------------------------------------------------------------------------- } procedure THeaderListBox.UpdateChanges(Sender: TObject); var i : Integer; HS: THeaderSection; begin if Assigned(Settings) and Assigned(FHeaderControl) then begin FHeaderControl.Sections.Clear; for i := 0 to Settings.HeaderCount-1 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; { ---------------------------------------------------------------------------- } 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; DoChanges; end; end; { ---------------------------------------------------------------------------- } procedure TSettings.SetFrameColor(Value: TColor); begin if Value <> FFrameColor then begin FFrameColor := Value; DoChanges; end; end; { ---------------------------------------------------------------------------- } procedure TSettings.SetTextColor(Value: TColor); begin if Value <> FTextColor then begin FTextColor := Value; DoChanges; end; end; { ---------------------------------------------------------------------------- } procedure TSettings.DoChanges; begin if Assigned(FOnEffectChange) then FOnEffectChange(Self); end; { ---------------------------------------------------------------------------- } end.
Let's fetz sprach der Frosch und sprang in den Mixer
|
Zitat |
Ansicht |
Linear-Darstellung |
Zur Hybrid-Darstellung wechseln |
Zur Baum-Darstellung wechseln |
ForumregelnEs ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus. Trackbacks are an
Pingbacks are an
Refbacks are aus
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
LinkBack URL |
About LinkBacks |