Q&A

  • {$R } 지시자로 로드한 리소스의 핸들은 어떻게 얻을 수 있나요?
안녕하십니까.

일종의 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.

2  COMMENTS
  • Profile
    최용일 2000.06.17 22:29
    안녕하세요. 최용일입니다.



    다른곳은 이상이 없습니다. 리소스로드도 제대로 했고요. 리소스 이름은 물론 맞겠죠...



    의심이 가는 부분은 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.

  • Profile
    김일영 2000.06.17 22:53
    답변에 감사드립니다.

    용일님께서 여러번 도와주시는데 보답 한번 변변히 못해드려서 송구스럽네요.

    TMapManagerSelectForSimpview은 저희가 만든 Action입니다만...

    잘 안되길래 사람들을 꼬드겨서 리소스 대신 리소스 DLL을 쓰기로 바꿨습니다.

    원래 이래선 안되지만... 프로젝트 하다 보니 기술적으로 타당하게 하는 것보다

    사람들을 잘 꼬드기는게 훨씬 현명한(?) 방법이 되는 경우가 많네요...

    아직은 그런 방법이 적응이 안되어선지 매우 찝찝합니다만...

    관심가지고 읽어주셔서 대단히 감사합니다.

    즐거운 주말 되십시오.

    =======================================================================

    최용일 wrote:

    > 안녕하세요. 최용일입니다.

    >

    > 다른곳은 이상이 없습니다. 리소스로드도 제대로 했고요. 리소스 이름은 물론 맞겠죠...

    >

    > 의심이 가는 부분은 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.