Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Format of a DLL (internal functions)

Posted on 2007-03-24
1
206 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 182
delphi parse string to params 3 136
How to debug For loops? 3 56
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 42
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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