在ocx中用指针,会有问题吗?
声明一个指向panel的指针,用来存储当前的panel对象,然后实现panel间的切换(通过panel.visble)
建一个全局变量
curpanel:^TPanel;
主要程序如下
procedure TActiveFormX.ActiveFormCreate(Sender: TObject);
begin
new(curpanel);
end;
procedure TActiveFormX.ActiveFormDestroy(Sender: TObject);
begin
dispose(curpanel);
end;
procedure TActiveFormX.showpanel(var panelx:TPanel);
var TempPanel:^TPanel;
begin
try
if CurPanel=nil then
begin
TempPanel:=@panelx;
CurPanel^ := TempPanel^;
curpanel^.Visible:=true;
end
else
begin
curpanel^.Visible:=false;
TempPanel:=@panelx;
CurPanel^:= TempPanel^;
curpanel^.Visible:=true;
end;
except
exit;
end;
end;
问题:在ocx使用时经常会出现panel无法正常切换的问题,不知道是什么问题,大家帮我看看程序是不是有bug,或着说在ocx下面这样做是不是有什么局限性?