Solved

inline methods in Delphi 3

Posted on 1997-10-08
7
372 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 70
Press three keys together and trigger a function 3 51
FMX and jaudiotracker playing memory stream 29 66
DBGrid or StringGrid ? 6 71
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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

14 Experts available now in Live!

Get 1:1 Help Now