Solved

inline methods in Delphi 3

Posted on 1997-10-08
7
374 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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