Delphi中inherited的详细用法

inherited就是调用祖先类的函数,如果不带参数就是默认调用同名函数
如果带参数则表明子类中的函数个数可能比祖先类要多取其中的几个参数传过去
例如
祖先类有个函数 Create(AName:string);
子类有个函数 Create(AName:string;AComponent:TObject);override;
那么子类的Create函数内就可以这样调用祖先类:
procedure TAClass.Create(AName:string;AComponent:TObject);
begin
    Inherited Create(AName);
end;

转自:http://zhidao.baidu.com/question/203581444.html

看完以上答案还是不太明白,看下面的:

这段话已经能够说的很清楚了啊。
如果有同名同参数的父类方法,
单独用inherited;就是继承父类的同名同参数方法。
如果inherited XXX(..), 说明父类有了同名的重载方法,你指定继承其中的一个方法。
转自:http://zhidao.baidu.com/question/107608343.html

看看这个例子,对理解有帮助:http://bbs.csdn.net/topics/10134234

总转自:http://www.cnblogs.com/devcjq/articles/2391550.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Linux平台上使用timer_create函数可以创建一个定时器。在Delphi,可以通过调用Linux系统库头文件来实现该函数的调用。下面是一个简单的示例代码: ```delphi unit LinuxTimer; interface uses LinuxApi; type TTimer = class private FTimerID: timer_t; FInterval: Cardinal; FOnTimer: TNotifyEvent; FIsStarted: Boolean; FTimerSpec: itimerspec; procedure SetInterval(const Value: Cardinal); public constructor Create; destructor Destroy; override; procedure Start; procedure Stop; property Interval: Cardinal read FInterval write SetInterval; property OnTimer: TNotifyEvent read FOnTimer write FOnTimer; property IsStarted: Boolean read FIsStarted; end; implementation uses SysUtils; { TTimer } constructor TTimer.Create; begin inherited; FTimerID := 0; FInterval := 1000; FIsStarted := False; end; destructor TTimer.Destroy; begin Stop; inherited; end; procedure TTimer.SetInterval(const Value: Cardinal); begin if FInterval <> Value then begin FInterval := Value; if IsStarted then begin Stop; Start; end; end; end; procedure TTimer.Start; begin if not IsStarted then begin FillChar(FTimerSpec, SizeOf(FTimerSpec), 0); FTimerSpec.it_interval.tv_sec := FInterval div 1000; FTimerSpec.it_interval.tv_nsec := (FInterval mod 1000) * 1000000; FTimerSpec.it_value.tv_sec := FInterval div 1000; FTimerSpec.it_value.tv_nsec := (FInterval mod 1000) * 1000000; if timer_create(CLOCK_REALTIME, nil, @FTimerID) = 0 then begin if timer_settime(FTimerID, 0, @FTimerSpec, nil) = 0 then FIsStarted := True else timer_delete(FTimerID); end; end; end; procedure TTimer.Stop; begin if IsStarted then begin FTimerSpec.it_interval.tv_sec := 0; FTimerSpec.it_interval.tv_nsec := 0; FTimerSpec.it_value.tv_sec := 0; FTimerSpec.it_value.tv_nsec := 0; timer_settime(FTimerID, 0, @FTimerSpec, nil); timer_delete(FTimerID); FIsStarted := False; end; end; end. ``` 这是一个简单的封装,使用时只需要创建一个TTimer对象,并调用Start方法就可以启动一个定时器。在该代码,使用了Linux API的timer_create和timer_settime函数来实现定时器功能。同时,该封装使用了Delphi的事件模型,通过设置OnTimer事件,在定时器到期时,会触发该事件,从而完成定时器任务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值