FreePascal-Lazarus的遗传
我正在学习使用Lazarus IDE的免费pascal,我不知道如何以派生形式继承方法 我想要这样的东西: 形式基础或父亲:FreePascal-Lazarus的遗传,pascal,lazarus,freepascal,Pascal,Lazarus,Freepascal,我正在学习使用Lazarus IDE的免费pascal,我不知道如何以派生形式继承方法 我想要这样的东西: 形式基础或父亲: procedure HelloWorld; begin ShowMessage('Hello World from base form or father'); end; 和派生形式或子项: procedure HelloWorld; begin inherited; ShowMessage('Hello World from derived form or
procedure HelloWorld;
begin
ShowMessage('Hello World from base form or father');
end;
和派生形式或子项:
procedure HelloWorld;
begin
inherited;
ShowMessage('Hello World from derived form or child');
end;
我希望结果通过单击显示2条消息(例如按钮1)
谢谢 在Pascal
中,过程
不是一种面向对象的编程结构
FreePascal包含过程,并且对象可以包含过程:在Pascal
中,过程
不是面向对象的编程结构
FreePascal包含和对象可以包含过程:要更好地了解对象Pascal语言,我相信您应该先阅读FreePascal参考指南。FreePascal是lazarus下面的底层编译器 理解表单、标签、按钮等是对象、实例、类等概念的具体体现是很重要的 在这方面,类是绑定代码和数据的结构。您想要实现的目标如下:
Type
TMyClass = Class(<ancestorclass>)
<fields and methods>
End;
TMyChildClass = Class(TMyClass)
<fields and methods>
End;
TMyClass = Class /* No parenthesis or ancestor name means the class derives from TObject */
Procedure ParentMethod;
End;
TMyChildClass = Class(TMyClass)
Procedure ParentMethod; Override;
End;
Procedure TMyClass.ParentMethod;
Begin
DoSomething;
End;
Procedure TMyChildClass.ParentMethod; /* Dont repeat the override */
Begin
Inherited; // This will call the parents method
End;
这是在对象pascal中执行方法重写的正确方法。如果要使用“inherited”的类的定义没有括号和祖先类的名称,则then和inherited之间没有祖先关系,这将无法实现您期望的功能。为了更好地了解对象Pascal语言,我相信你应该从阅读freepascal参考指南开始。FreePascal是lazarus下面的底层编译器 理解表单、标签、按钮等是对象、实例、类等概念的具体体现是很重要的 在这方面,类是绑定代码和数据的结构。您想要实现的目标如下:
Type
TMyClass = Class(<ancestorclass>)
<fields and methods>
End;
TMyChildClass = Class(TMyClass)
<fields and methods>
End;
TMyClass = Class /* No parenthesis or ancestor name means the class derives from TObject */
Procedure ParentMethod;
End;
TMyChildClass = Class(TMyClass)
Procedure ParentMethod; Override;
End;
Procedure TMyClass.ParentMethod;
Begin
DoSomething;
End;
Procedure TMyChildClass.ParentMethod; /* Dont repeat the override */
Begin
Inherited; // This will call the parents method
End;
这是在对象pascal中执行方法重写的正确方法。如果要使用“inherited”的类的定义没有括号和祖先类的名称,那么then和inherited之间没有祖先关系将不会执行您希望执行的操作