Witam, pisze komponencik w stylu TJvDBNavigator do obsługi bazy od podstaw, no i natknąłem się na problem, mianowicie, tenże komponent jest kolekcją przycisków TSpeedButton, i jedną z jego właściwości jest link do TImageList, czyli do obrazków, które będą wyświetlane na przyciskach. I tu powstają dwie kwestie do rozwiązania -> pierwszą jest to, że w trybie edycji ikonki faktycznie są widoczne na buttonach natomiast po odpaleniu już nie ? (Metoda Paint ?) druga kwestia to brak pojawiania się kolejnych obrazków na buttonach po dodaniu do TImageList (jedynie po ponownym zlinkowaniu właściwości komponentu) (może wysyłanie komunikatu do TImageList albo odwrotnie ?)
dzięki za jakiekolwiek wskazówki pozdrawiam
sorry za błąd w tytule
kod wygląda tak:
TITDBNavigateButton = class(TSpeedButton)
private
protected
procedure Paint; override;
public
destructor Destroy; override;
end;
TITDBNavigator = class(TCustomPanel)
private
function CountVisibleButtons(): integer;
procedure ResizeButtons();
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure SetImageList(const Value: TImageList);
protected
Images: TImageList;
Buttons: array[0..8] of TITDBNavigateButton;
VisibleButtons: set of TITDBNavigateButtonNames;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ImageList: TImageList read Images write SetImageList;
end;
procedure Register;
implementation
destructor TITDBNavigateButton.Destroy;
begin
inherited;
end;
procedure TITDBNavigateButton.Paint;
begin
inherited;
end;
function TITDBNavigator.countVisibleButtons: integer;
var
i: integer;
res: integer;
begin
res := 0;
for i := Low(buttons) to High(buttons) do
begin
if (buttons[i].Visible = True) then inc(res);
end;
result := res;
end;
constructor TITDBNavigator.Create(AOwner: TComponent);
var
i: integer;
begin
inherited Create(AOwner);
self.Width := 240;
self.Height := 35;
for i := Low(buttons) to High(buttons) do
begin
Buttons[i] := TITDBNavigateButton.Create(self);
Buttons[i].Parent := self;
Buttons[i].Visible := True;
end;
resizeButtons();
end;
procedure Register;
begin
RegisterComponents('IT', [TITDBNavigator]);
end;
destructor TITDBNavigator.Destroy;
begin
inherited;
end;
procedure TITDBNavigator.Paint;
begin
inherited;
end;
procedure TITDBNavigator.ResizeButtons;
var
i, count, which, width: integer;
begin
which := round(self.Width / (High(buttons) + 1));
self.Width := which * (High(buttons) + 1);
count := countVisibleButtons();
if (count > 0) then
begin
which := 0;
width := round(self.Width / count);
for i := Low(buttons) to High(buttons) do
begin
if (Buttons[i].Visible) then
begin
Buttons[i].SetBounds(which * width, 0, width, self.Height);
inc(which);
end;
end;
end;
end;
procedure TITDBNavigator.SetImageList(const Value: TImageList);
var
i: integer;
begin
Images := Value;
if (not(csLoading in ComponentState) and (Images <> nil)) then
begin
for i := Low(Buttons) to High(Buttons) do
begin
if (i < Images.Count) then
begin
Images.GetBitmap(i, Buttons[i].Glyph);
Buttons[i].Invalidate;
end;
end;
end;
if (Value <> nil) then Value.FreeNotification(Self);
end;
procedure TITDBNavigator.WMSize(var Message: TWMSize);
begin
inherited;
ResizeButtons();
end;
...