Solved

Format of a DLL (internal functions)

Posted on 2007-03-24
1
204 Views
Last Modified: 2010-04-05
I'm rather lost in my first attempt to create a Delphi 5 DLL.

Yes, I can run through the wizard and get the following barebones shell for my library...

// ===========================
library test;

uses
  SysUtils, Classes;

{$R *.RES}

function TestStrings(FirstParam: ShortString; SecondParam: ShortString):ShortString; stdcall;
begin
  Result := FirstParam + ', ' + SecondParam;
end;

exports TestStrings;

begin
end.

// ===========================

Everything is fine...until I want to start adding more code.

For instance, I am lost as to how to add new INTERNAL functions/procedures.  IOW, if I wanted the TestStrings function to use another function, which will only be used within the DLL and NOT be exported, then where/how does one define the function?  Do I do this...

// ===========================
library test;

uses
  SysUtils, Classes;

function AddBrackets(TextIn : ShortString) : ShortString;

{$R *.RES}

function TestStrings(FirstParam: ShortString; SecondParam: ShortString):ShortString; stdcall;
begin
  Result := FirstParam + ', ' + SecondParam;
end;

function AddBrackets(TextIn : ShortString) : ShortString;
begin
  Result := '<' + TextIn + '>';
end;

exports TestStrings;

begin
end.

// ===========================


...or this...

// ===========================
library test;

uses
  SysUtils, Classes;

function AddBrackets(TextIn : ShortString) : ShortString;

{$R *.RES}

function TestStrings(FirstParam: ShortString; SecondParam: ShortString):ShortString; stdcall;
begin
  Result := FirstParam + ', ' + SecondParam;
end;

exports TestStrings;

begin

function AddBrackets(TextIn : ShortString) : ShortString;
begin
  Result := '<' + TextIn + '>';
end;

end.

// ===========================

Neither of the above will compile, with the last example above generating the compile error "EXPORTS allowed only at global"

I can't find anything via googling that provides primer information regarding where to place INTERNAL functions/procedures in respect to exported function(s).
0
Comment
Question by:Kapusta
1 Comment
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 125 total points
ID: 18786548
Do you only want to use it within the same function or for many?
If so you can embed procedures inside other procedures.

function TestStrings(FirstParam: ShortString; SecondParam: ShortString):ShortString; stdcall;

   function AddBrackets(TextIn : ShortString) : ShortString;
   begin
     Result := '<' + TextIn + '>';
   end;

begin
  Result := AddBrackets( FirstParam + ', ' + SecondParam);
end;
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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

948 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

21 Experts available now in Live!

Get 1:1 Help Now