Q&A

  • 컴포넌트포함한 컴포넌트 만들기에서 에러...
아래 소스코드에서 Access Violation에러가 나는데 어느 부분에서 나는 거죠? 그리고 해결책은?

제 생각엔 LPanel과 RPanel의 Caption설정부분이 이상한 것같은데요.

디자인시에 LPanel,RPanel의 Caption이 LCaption,RCaption속성에 따라 변경되려면 더 추가해야 할 것이 있는지?



unit PPanel;



interface



uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

Forms, Dialogs, ExtCtrls, Buttons, StdCtrls;



type

TPPanel = class(TPanel)

private

{ Private declarations }

FLPanel: TPanel;

FRPanel: TPanel;

FLCaption: string;

FRCaption: string;

protected

{ Protected declarations }

public



{ Public declarations }

constructor Create(AOwner: TComponent); override;

procedure SetFLCaption(s: string);

procedure SetFRCaption(s: string);

published

{ Published declarations }

property LTitle: string read FLTitle write SetFLCaption;

property RTitle: string read FRTitle write SetFRCaption;

end;



procedure Register;



implementation



procedure TPPanel.SetFLCaption(s: string);

begin

FLPanel.Caption:=s;

FLCaption := s;

end;



procedure TPPanel.SetFRCaption(s: string);

begin

FRPanel.Caption:=s;

FRPanel := s;

end;



constructor TPPanel.Create(AOwner: TComponent);



begin

inherited Create(AOwner);

Width := 131;

Height := 150;

FLPanel := TPanel.Create(Self);

FLPanel.BevelInner:=True;

FLPanel.SetBounds(0, 0, (width div 3), 25);

FLPanel.Parent := Self;

FRPanel := TPanel.Create(Self);

FRPanel.BevelInner:=True;

FRPanel.SetBounds(26, 0, (width - (width div 3)), 25);

FRPanel.Parent := Self;

end;



procedure Register;

begin

RegisterComponents('Samples', [TPPanel]);

end;



end.



{ This code came from Lloyd's help file! }

1  COMMENTS
  • Profile
    전철호 1999.06.21 20:22
    박성훈 께서 말씀하시기를...

    > 아래 소스코드에서 Access Violation에러가 나는데 어느 부분에서 나는 거죠? 그리고 해결책은?

    > 제 생각엔 LPanel과 RPanel의 Caption설정부분이 이상한 것같은데요.

    > 디자인시에 LPanel,RPanel의 Caption이 LCaption,RCaption속성에 따라 변경되려면 더 추가해야 할 것이 있는지?

    >

    > unit PPanel;

    >

    > interface

    >

    > uses

    > SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

    > Forms, Dialogs, ExtCtrls, Buttons, StdCtrls;

    >

    > type

    > TPPanel = class(TPanel)

    > private

    > { Private declarations }

    > FLPanel: TPanel;

    > FRPanel: TPanel;

    > FLCaption: string;

    > FRCaption: string;

    > protected

    > { Protected declarations }

    > public

    >

    > { Public declarations }

    > constructor Create(AOwner: TComponent); override;

    > procedure SetFLCaption(s: string);

    > procedure SetFRCaption(s: string);

    > published

    > { Published declarations }

    > property LTitle: string read FLTitle write SetFLCaption;

    > property RTitle: string read FRTitle write SetFRCaption;

    > end;

    >

    > procedure Register;

    >

    > implementation

    >

    > procedure TPPanel.SetFLCaption(s: string);

    > begin

    > FLPanel.Caption:=s;

    > FLCaption := s;

    > end;

    >

    > procedure TPPanel.SetFRCaption(s: string);

    > begin

    > FRPanel.Caption:=s;

    > FRPanel := s;

    > end;

    >

    > constructor TPPanel.Create(AOwner: TComponent);

    >

    > begin

    > inherited Create(AOwner);

    > Width := 131;

    > Height := 150;

    > FLPanel := TPanel.Create(Self);

    > FLPanel.BevelInner:=True;

    > FLPanel.SetBounds(0, 0, (width div 3), 25);

    > FLPanel.Parent := Self;

    > FRPanel := TPanel.Create(Self);

    > FRPanel.BevelInner:=True;

    > FRPanel.SetBounds(26, 0, (width - (width div 3)), 25);

    > FRPanel.Parent := Self;

    > end;

    >

    > procedure Register;

    > begin

    > RegisterComponents('Samples', [TPPanel]);

    > end;

    >

    > end.

    >

    > { This code came from Lloyd's help file! }



    안녕하세요.. 전철호입니다.

    귀하께서 만든 콤포넌트 소스를 보니

    Destructor부분이 없네요.

    없어도 되지만 귀하께서 작성한 코딩을 보면

    꼭 필요합니다.

    TPanel Component에 두개의 Panel 콤포넌트를 메모리에서

    제거하는 부분이 필요하거든요..



    FLPanel.Free;

    FRpanel.Free;

    inherited destroy;



    이부분을 넣으면 아마 Access Violation에러가 나지 않을 것 같네요.

    아마 콤포넌트 제거시 이에러가 날 것 같은데.



    참고) 귀하께서 만든 콤포넌트는 리소스가 많이 먹겠군요.

    패널이 세게이니까요.

    그러지마시고 Tcustomcontrol에서 상속을 받아서

    Paint부분에서 윈도우를 두개로 분활되는 효과를 주어서

    하면은 아마 리소스도 쩍고 훨씬 낳은 콤포넌트가 될것 같네요.

    그리고 제홈페이지에 가셔서 개발콤포넌트부분에 가면은

    이와 비슷한 Component가 있습니다.

    TJeonLabel이것은 수평이 아니라 수직으로 되어 있는

    것입니다.

    콤포넌트를 다운 받아서 테스트를 해보세요.

    단 Shareware버전입니다.