使用RAD XE在Delphi中自动执行其他方法之前的方法 [英] Automatically execute a method before another methods in Delphi with RAD XE

查看:139
本文介绍了使用RAD XE在Delphi中自动执行其他方法之前的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,

我编写了某些类 TFoo TBar 。他们有一些方法需要调用切换功能 TFoo.switch TBar.switch

I code some classes TFoo and TBar. They have a few of methods that need calling a swithcing function TFoo.switch and TBar.switch.

TBaseFooBar = class
  strict private
    FNumConfig: Word;
  protected
    procedure Switch;  
end;

此超类具有一个专用字段 FNumConfig 其中描述了PCI卡的编号。 Switch 方法使用某些库中的函数:

This super class has a private field FNumConfig which describe the number of PCI-card. The Switch method uses function from some library:

procedure TBaseFooBar.Switch;  
begin
  tmkselect(FNumConfig);
end;

我想问一下您是否可以调用上级函数在分别执行任何 DoSomethingWithFoo() DoSomethingWithBar()之前切换
我的意思是这样的

I would like to ask you is there a way to call a super function Switch before executing any DoSomethingWithFoo() or DoSomethingWithBar() respectivly? I mean something like this

TFoo = class(TBaseFooBar )
  { FNumConfig: Word; // this number declares the number of a PCI card}
  public 

  @Switch // before this method
  procedure DoSomethingWithFoo1();

// ...
  @Switch // and before this one
  procedure DoSomethingWithFooN();

// before this one there is no calling of Switch
  function NotSwitching();
end;

TBar

TBar = class(TBaseFooBar )
{  FNumConfig: Word; // this is another one number declares of another PCI card, they are not equal. }
public 
@Switch // before this method
  procedure DoSomethingWithBar1();
// ...
@Switch // and before this one
  procedure DoSomethingWithBarN();
end;

我知道一个简单的方法:

I know about a simple method:

procedure TFoo.DoSomethingWithFoo1();  
begin
Switch();
// and another stuff.
end;

但我想将所有内容都写在一个地方-类的声明中。

but I would like to write all it in one place - in a declaration of classes.

推荐答案

Delphi不支持内置的功能。您所要的本质是面向方面的编程功能。第三方供应商提供了一些选项,之前已经在此处进行了讨论

Delphi doesn't support anything like that built in. What you're asking for is essentially an aspect-oriented-programming feature. There are some options for that from third-party vendors, which have been discussed here before.

这篇关于使用RAD XE在Delphi中自动执行其他方法之前的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆