主窗体frmCrmi中创建子窗体:
if not Assigned(frmCrmi_1) then
begin
frmCrmi_1 := TfrmCrmi_1.Create(self);
end;
frmCrmi_1.ShowModal;
在子窗体中:
FOwner: TComponent;
constructor TfrmCrmi_1.Create(AOwner: TComponent);
begin
inherited;
FOwner := AOwner;//这个FOwner应该就是主窗体对吗?
end;在子窗体中调用主窗体的方法:
TfrmCrmi(Fowner).serch();//这里可以frmCrmi.serch();吗?有点拎不清
if not Assigned(frmCrmi_1) then
begin
frmCrmi_1 := TfrmCrmi_1.Create(self);
end;
frmCrmi_1.ShowModal;
在子窗体中:
FOwner: TComponent;
constructor TfrmCrmi_1.Create(AOwner: TComponent);
begin
inherited;
FOwner := AOwner;//这个FOwner应该就是主窗体对吗?
end;在子窗体中调用主窗体的方法:
TfrmCrmi(Fowner).serch();//这里可以frmCrmi.serch();吗?有点拎不清
procedure TfrmCrmi.Initialize;
begin
inherited;
CreateInstance('Crmi');
end;
//基类
function TfrmChildBase.CreateInstance(ClassName: String): Integer;
begin
JInstanceID:=0;
....
end;
//主窗体的serch方法
function TfrmCrmi.serch(TS1: String): Boolean;
Var
Protocol : TBzProtocol;
Index : Integer;
sResult : String;
begin
inherited;
Result := False;
Protocol := TBzProtocol.Create;
try
Protocol.ClearAll;
Index:=Protocol.AddParam;
sResult := Invoke(JInstanceID,'serch',Protocol.text);
Protocol.GetResultContext(sResult);
if Protocol.ResultStatus >= 0 then
begin
Result := true;
end
else
begin
ShowInfoTxt(DM_ERROR,Protocol.ResultErrorInfo);
end;
finally
FreeAndNil(Protocol);
end;
end;
//子窗体的创建(子窗体继承另外一个父类)
if not Assigned(frmCrmi_1) then
begin
frmCrmi_1 := TfrmCrmi_1.Create(self);
end;
frmCrmi_1.ShowModal;
//子窗体
private
FOwner: TComponent;
public
constructor Create(AOwner: TComponent); override;
constructor TfrmCrmi_1.Create(AOwner: TComponent);
begin
inherited;
FOwner := AOwner;
end;
//子窗体的调用主窗体的方法
procedure TfrmCrmi_1.btnFlatSpeedButton1Click(Sender: TObject);
begin
//这里如果用frmCrmi.serch(ts1);就会报错,我跟踪了一下,在主窗体的JInstanceID出错
if TfrmCrmi(Fowner).serch(TCrmi020DM(DM1).mtblTs.FieldByName('TS1').AsString) then
Close
else
begin
MessageBox('提示:','查询失败!',DM_INFO);
Exit;
end;
end;