예 코드를 통해 이벤트 처리기를 할당하면 작동합니다.
이벤트 처리기에서 ClientData 인스턴스의 항목을 사용하지 않는 경우 (권장) 인스턴스를 만들지 않아도됩니다.
TClientData 유형의 nil 변수이면 충분합니다.
아래 샘플 응용 프로그램에서는 ClientData 모듈이 dpr에 의해 자동 생성되지 않고 nil로 유지됩니다. 그렇다고해서 이벤트 처리기가 올바르게 작동하는 것을 방해하지는 않습니다.
DPR
program Project2;
uses
Forms,
Unit10 in 'Unit10.pas' {Form10},
Unit11 in 'Unit11.pas' {ClientData: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm10, Form10);
Application.Run;
end.
폼 DFM
object Form10: TForm10
Left = 0
Top = 0
Caption = 'Form10'
ClientHeight = 282
ClientWidth = 418
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 168
Top = 168
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
폼 PAS
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unit11, StdCtrls;
type
TForm10 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form10: TForm10;
implementation
{$R *.dfm}
procedure TForm10.Button1Click(Sender: TObject);
begin
if ClientData = nil then
ShowMessage('ClientData is nil')
else
ShowMessage('ClientData is NOT nil');
end;
procedure TForm10.FormCreate(Sender: TObject);
begin
OnClick := ClientData.WhateverEvent;
end;
end.
데이터 모듈의 DFM
object ClientData: TClientData
OldCreateOrder = False
Height = 150
Width = 215
end
,
the DataModule pas
unit Unit11;
interface
uses
SysUtils, Classes, Windows;
type
TClientData = class(TDataModule)
procedure WhateverEvent(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ClientData: TClientData;
implementation
{$R *.dfm}
procedure TClientData.WhateverEvent(Sender: TObject);
begin
MessageBox(0, PChar('Sender is ' + Sender.ClassName), 'Test', MB_ICONINFORMATION or MB_OK);
end;
end.
내 편집 addon. ClientData는 싱글 톤 클래스에 대한 전역 참조입니다. 작동하지만 여전히 거절해야합니다. –
Ok. 시간을 디자인하는 대신 런타임에 이벤트 처리기를 할당 해 보았습니까? 예 : 양식의 OnCreate. 디자인 시간 문제가 cxGrid의 다소 '비정상적인'디자인 때문인지 궁금합니다. 그것은 TcxGridSite와 그리드 뷰 등의 모든 조합입니다. 따라서 OnEnter 메서드는 폼에서 예상대로 보이지 않습니다. 그래도 잘못 될 수 있습니다 ... – shunty
아마도 cxGrid의 기이함과 관련이없는 것 같습니다. D2010에서는 오브젝트 인스펙터를 사용하여 다른 모듈의 컴포넌트 참조를 지정할 수 있지만 런타임에만 메소드/이벤트 핸들러를 지정할 수는 없습니다. 내가 말할 수있는 한. – shunty