我正在尝试将表单中定义的过程分配给数据源的事件 OnStateChange,如下所示:
unit SDIMAIN;
interface
uses Windows, ....., DB ;
type
TSDIAppForm = class(TForm)
....
procedure datasourceOnStateChange(Sender: TObject);
private
stateChange : TNotifyEvent;
....
var
SDIAppForm: TSDIAppForm;
...
end;
procedure TSDIAppForm.FormCreate(Sender: TObject);
begin
DataModule1.AdsTable1.Active := true;
DataModule1.AdsTable2.Open;
stateChange := SDIAppForm.datasourceOnStateChange(DataModule1.AdsTable1);
DataModule1.DataSource1.OnStateChange := stateChange;
.
.
.
procedure TSDIAppForm.datasourceOnStateChange(Sender: TObject);
begin...end;
最初,当我尝试执行上述操作时,我得到了错误!不兼容的类型:“TNotifyEvent”和“过程、无类型指针或无类型参数”
I tried changing
stateChange := SDIAppForm.datasourceOnStateChange(DataModule1.AdsTable1); to
stateChange := SDIAppForm.datasourceOnStateChange;
Now I don't get the error but it doesn't work. The OnStateChange event is not fired at all.
I tried with other methods like using
var
Method : TMethod;
.
.
.
Method.Data := Pointer(Self);
Method.Code := MethodAddress('datasourceOnStateChange'); and using pointers but it doesn't work.
我是 delphi 新手,目前正在学习。我可能不明白到底应该做什么。如果有人可以帮助我解决这个问题,那将非常有帮助。
Thanks.