안녕하십니까.
일종의 SpeedButton 컴포넌트를 만들고 있는데,
저희 프로젝트에서 정의한 Action들이 있고 그 Action중 어떤 것을
선택하느냐에 따라 자동으로 Glyph이 바뀌도록 하고자 합니다.
Glyph에 사용할 Bitmap들은 TestSpeedButton.res에 들어 있습니다.
그래서 다음과 같은 코드를 작성하였으나 원하는대로 Bitmap을
바꾸어주지는 못하더군요.
이것이 Glyph.LoadFromResourceName에 인자로 사용한 HInstance가
적절하지 않아서인지 잘 모르겠습니다만 아마 그렇지 않은가 생각하고 있습니다.
다른 부분의 문제인지도 잘 모르겠습니다.
도움 주시면 대단히 감사하겠습니다.
==============================================================
unit TestSpeedButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, UtkActns;
type
TTestSpeedButton = class(TSpeedButton)
private
{ Private declarations }
protected
{ Protected declarations }
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean);
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
{$R TestSpeedButton.RES}
procedure TTestSpeedButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
inherited ActionChange(Sender, CheckDefaults);
if Sender is TMapManagerSelectForDetailView then begin
Glyph.LoadFromResourceName(HInstance, 'DETAILVIEW');
end
else if Sender is TMapManagerSelectForSimpView then begin
Glyph.LoadFromResourceName(HInstance, 'SIMPVIEW');
end
else begin
Glyph := nil;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TTestSpeedButton]);
end;
end.
다른곳은 이상이 없습니다. 리소스로드도 제대로 했고요. 리소스 이름은 물론 맞겠죠...
의심이 가는 부분은 Sender파라매터입니다. TMapManagerSelectForSimpView이 객체가 어떤
형인줄은 잘 모르겠는데 아마도 이 객체는 이름으로 추측컨데 TAction객체는 아니리라고
생각합니다. 그래서 스피드버튼의 Glyph가 항상 nil일 것입니다.
ActionChange메소드에서 Sender파라매터로 넘어오는 객체는 TAction형입니다.
이 Sender파라매터를 검사하는 부분이 아마도 TAction객체가 아니어서 항상 Glyph가 nil이
되는것 같네요.
if Sender is TMapManagerSelectForDetailView then begin <===
// Sender = TAction <> TMapManagerSelectForDetailView
^^ 항상 즐코하세요.
김일영 wrote:
> 안녕하십니까.
> 일종의 SpeedButton 컴포넌트를 만들고 있는데,
> 저희 프로젝트에서 정의한 Action들이 있고 그 Action중 어떤 것을
> 선택하느냐에 따라 자동으로 Glyph이 바뀌도록 하고자 합니다.
> Glyph에 사용할 Bitmap들은 TestSpeedButton.res에 들어 있습니다.
> 그래서 다음과 같은 코드를 작성하였으나 원하는대로 Bitmap을
> 바꾸어주지는 못하더군요.
> 이것이 Glyph.LoadFromResourceName에 인자로 사용한 HInstance가
> 적절하지 않아서인지 잘 모르겠습니다만 아마 그렇지 않은가 생각하고 있습니다.
> 다른 부분의 문제인지도 잘 모르겠습니다.
> 도움 주시면 대단히 감사하겠습니다.
> ==============================================================
> unit TestSpeedButton;
>
> interface
>
> uses
> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
> Buttons, UtkActns;
>
> type
> TTestSpeedButton = class(TSpeedButton)
> private
> { Private declarations }
> protected
> { Protected declarations }
> procedure ActionChange(Sender: TObject; CheckDefaults: Boolean);
> public
> { Public declarations }
> published
> { Published declarations }
> end;
>
> procedure Register;
>
> implementation
>
> {$R TestSpeedButton.RES}
>
> procedure TTestSpeedButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);
> begin
> inherited ActionChange(Sender, CheckDefaults);
> if Sender is TMapManagerSelectForDetailView then begin
> Glyph.LoadFromResourceName(HInstance, 'DETAILVIEW');
> end
> else if Sender is then begin
> Glyph.LoadFromResourceName(HInstance, 'SIMPVIEW');
> end
> else begin
> Glyph := nil;
> end;
> end;
>
> procedure Register;
> begin
> RegisterComponents('Samples', [TTestSpeedButton]);
> end;
>
> end.