回 帖 发 新 帖 刷新版面

主题:inherited???????

什么是inherited?谁能给些经典的小程序让我看懂?

回复列表 (共2个回复)

沙发

就是继承父类的某个方法的运算阿。

后面不跟函数时表示该方法先进行父类的统一方法的运算。

本人的一个实战的例子:

TDataInfo类中有以下方法:

Procedure TDataInfo.GetTDataInfo(StrList:TStrings);
Var
  Str:String;
begin
  StrList.Add('    En_CreatedFrom:'+En_DataCreatedFromtoStr(En_CreatedFrom));
  StrList.Add('    CreatedBy:'+CreatedBy);
  StrList.Add('    CreatedDate:'+MyDatetoStr(CreatedDate,'/'));
  StrList.Add('    DataAcqLoc:'+DataAcqLoc);
  StrList.Add('    DataAcqSystem:'+DataAcqSystem);
  StrList.Add('    Operator:'+Operator);
  StrList.Add('    OrigFile:'+OrigFile);
  StrList.Add('    Othersinfo:'+OthersInfo);
  StrList.Add('    RefLocate:'+RefLoc);
  StrList.Add('    En_RefType:'+En_RefTypetoStr(En_Reftype));
  StrList.Add('    RefLatitude:'+MyBLtoStr(RefLat,':'));
  StrList.Add('    RefLongitude:'+MyBLtoStr(RefLong,':'));
  StrList.Add('    RefElev:'+FloattoStr(RefElev));
  StrList.Add('    Set_ZAB:'+Set_ZTABtoStr(Set_ZAB));
  StrList.Add('    Set_TAB:'+Set_ZTABtoStr(Set_TAB));
  StrList.Add('    En_ZVar:'+En_ZTVartoStr(En_ZVar));
  StrList.Add('    En_TVar:'+En_ZTVartoStr(En_TVar));
end;

现在
TSiteDataInfo=Class(TDataInfo);
在TSiteDataInfo类中有同样的方法,其实现过程为:
Procedure TSiteDataInfo.GetTDataInfo(StrList:TStrings);
begin
  Inherited ;
  StrList.Add('    Lx:'+FloattoStr(Lx));
  StrList.Add('    Ly:'+FloattoStr(Ly));
  StrList.Add('    En_InvFwdMod:'+En_InvFwdModtoStr(En_InvFwdMod));
  StrList.Add('    Set_InvFwdCurve:'+Set_invFwdCurvetoStr(Set_InvFwdCurve));
end;

即首先进行父类中的运算,然后进行添加的运算。这样可以带来很多方便。

板凳


[em4]明白了,谢谢~

我来回复

您尚未登录,请登录后再回复。点此登录或注册