How can I make Class Completion include parentheses even for empty parameter lists?

北慕城南 提交于 2019-12-10 16:14:36

问题


I'm back in Delphi 2010 again after having worked several years in Visual Studio. I would like to make the IDE behave in a differnet way:

I'd like the IDE's auto-completion to respect the parenthesis when I declare a function/procedure. Example: if I declare procedure x(); Id like the auto-completion to create procedure myobj.x(); and NOT procedure myobject.x; as it does. Yes, it doesn't really matter but I'm pedantic. Any ideas?


回答1:


Delphi doesn't require the parentheses when there are no parameters; I doubt this is possible.

It shouldn't matter in the interface or implementation, where the fact that it's a method declaration is clear.

function TMyClass.IsDefaultPropValue: Boolean;

I can see where it would matter in actual code that calls the method, where you would want to clarify that it was not a variable, as in

// Unit MyClass
type
  TMyClass=class(TSomething)
  public
    function IsDefaultPropValue: Boolean;
  end;

// In a far distant block  of code in another unit that uses the above unit, using the
// nasty "with" (not you, of course - one of your coworkers):
with MyClassInstance do
begin
  // More lines of code. FirstPass is a local boolean variable.
  if FirstPass then
  begin
    if IsDefaultPropValue then
    begin
      // More lines of code
    end
    else
    begin
      // Alternate branch of code 
    end;
  end
  else
  begin
    if IsDefaultPropValue then
    //.....
  end;
end;

In this case, it's not clear that IsDefaultPropValue is a function and not a Boolean variable and I'd use it as

if IsDefaultPropertyValue() then ... 

// or better yet: 
if MyClassInstance.IsDefaultPropValue() then ...

to make it clear.




回答2:


AFAIK, there's no way.

Object Pascal doesn't require parenthesis when you have (as Ken said) no parameters - so it's harmless.

PS.: The need for parenthesis even for non-parameterized routines is one of the most pesky and irritant things in VS languages (particularly in VB.NET). Of course, it's just IMHO...



来源:https://stackoverflow.com/questions/7908372/how-can-i-make-class-completion-include-parentheses-even-for-empty-parameter-lis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!