Solved

inline methods in Delphi 3

Posted on 1997-10-08
7
371 Views
Last Modified: 2010-04-04
How do I use the reserved word "inline" in Delphi 3?
I would also like to know if there is more than one way to use inline methods, like in C++ - you can write the implementation in the declaration part (.h file), or type "inline" and implement the method in the definition part (.cpp file).

Thanx, Westley.
0
Comment
Question by:Westley
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:dionysos_swamp
ID: 1346956
inline is not the same as in C++ it's a stupid way of throwing in hand-assembled code into the program, it's not really usefull as the asm .. end; can assemble everything now, it's a relic from Turbo Pascal.

an example:
 inline($cd, $19);

this would reboot (maybe) the PC under DOS-TP

... Afik


0
 

Author Comment

by:Westley
ID: 1346957
I read in a Delphi 2 book that Borland no longer supports inlines. It's still a reserved word, but it doesn't do anything.

But, OTOH, I heard there were inline methods in Turbo Pascal 7, and Borland said they keep backward compatibility. So who's right?
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1346958
The question has a simple anwer: You can not use the Inline directive in Delphi 3.0 (nor in the earlier versions of Delphi).

The word Inline is reserved but not understood by the compiler. This means that can not use it in the expected way:

Procedure Foo;  Inline;
Begin ... End;

nor can you define you own identifier called Inline.

So, what do you do in stead? Well, the closest you can come to an Inline procedure is to use the $INCLUDE compiler directive.
Suppose you want to make an inline procedure with a number of statements:

Procedure Foo;  Inline;
Begin
  Statement1;
  ...
  StatementN
End;

While you can not do this directly, you can create a file (e.g. FOO.PAS) containing the statements from the procedure body.  Now, at every point in your source code where you would like to 'call' this procedure, you put the command {$INCLUDE FOO.PAS}.

How this will help you.

AndersWP
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Westley
ID: 1346959
AndersWP,

This still doesn't help me with the biggest advantage of the inline concept: The ability to use private members outside the class.
For example, in C++, if you have declared
  int X;
inside a class, and it's private, you can still access it using
  int GetX() { return(X); }
and you don't get the overhead of using a real function.
Now Delphi supports properties, but I don't think properties are implemented inline, and since I'm using some private fields and exporting them via one-line-methods, I would like to know that I don't pay a high price for them.
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1346960
If the purpose of the excercise is to expose private fields in a controlled manner, properties is the way to go. The Delphi analog of your C++ example would be:

TMyClass = Class
Private
  FX: Integer;    
Public
  Property X: Integer Read FX;    
End;

Note that there is no Get function involved - you access the variable directly without the function call overhead.

Greetings,
AndersWP
0
 

Author Comment

by:Westley
ID: 1346961
Sorry I have to reject it again.

As I already wrote, I know about properties, but I need to know how they are implemented - are they like a macro, or a full function call?

My class looks like this:

TPrivClass = class
  public
    function func1(S: String): Boolean;
    function func2(S: String): Boolean;

MyClass = class
  private
    PrivClass: TPrivClass;
...
end;

I want people to be able to use func2 only, therefore I made the class private. But I can't just write
  property funcy1[S; String]: // referring to MyFunc2
because I want to do some validity check on S, say - lowercase it. So I add:

function MyClass.MyFunc2(S:String): Boolean;
begin
  Result := PrivClass.func2(AnsiLowerCase(S));
end;

but now I'm adding the overhead of calling a function.
And I have dozens of those things all around my project.
Even worse - sometimes my property calls another property of the private class, so I end up having 3 or 4 one-line functions calling each other.

Hope this explains my problem, and thanks for the effort,

  Westley.
0
 
LVL 1

Accepted Solution

by:
AndersWP earned 100 total points
ID: 1346962
Okay - now I think I get the picture. Alas, to the best of my knowledge, what you want to do is not possible. I do not think that you can avoid the overhead of a function call.
But look at the bright side: As you add validation code to your function, the significance of the function call overhead is diminished. Plus, your code gets more compact with function calls than with inline code. Unless timing is really critical, I would let it rest if I were you.

Greetings,
AndersWP
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now