Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:24:55+00:00 2026-06-14T10:24:55+00:00

For example in Pascal, if I had a library that I’m compiling to DLL:

  • 0

For example in Pascal, if I had a library that I’m compiling to DLL:

library Blah;

procedure AddToNum;
begin
  Num := Num + 1;
end;


procedure PrintNum;
begin
  WriteLN(Num);
end;

Exports AddToNum;
Exports PrintNum;


var
  Num: Integer;

begin
  Num := 0
end.

Ideally, the user could just call the AddToNum and PrintNum routines and it would do as such. However, you actually have to pass in arguments, and that means the user has to keep track of ALL of the variables I’d be using. What is the ideal method to do this? Pointers or something?

I’m looking for the variable to be the same between functions calls, much like some sort of “global”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:24:56+00:00Added an answer on June 14, 2026 at 10:24 am

    Move your DLL code (the actual code that runs) into a separate unit (for instance, DLLCode.pas), declare the variable at the top of the implementation section, and have your .DPR file just use that unit. All of the actual code goes in DLLCode.pas, and visibility of the variable follows the normal Pascal scoping rules.

    Here’s a sample DLL (DLLSample.dpr and DLLCode.pas), and a test console application that uses it. All of the code compiles and properly executes under Delphi 2007 and Windows 7 64-bit.

    DllSample.dpr:

    library DLLSample;
    
    { Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }
    
    uses
      SysUtils,
      Classes,
      DLLCode in 'DLLCode.pas';
    
    {$R *.res}
    
    begin
    end.
    

    DllCode.pas:

    unit DLLCode;
    
    interface
    
    procedure AddToNum; stdcall;
    procedure PrintNum; stdcall;
    
    exports
      AddToNum,
      PrintNum;
    
    implementation
    
    // Num  is only visible from here down, and starts with a value of zero when the
    // DLL is first loaded. It keeps it's value until the DLL is unloaded, which is
    // typically when your app is exited when using static linking, or when you 
    // FreeLibrary() when dynamically linking.
    var
      Num: Integer = 0;
    
    procedure AddToNum;
    begin
      Inc(Num);   // Same as Num := Num + 1;
    end;
    
    procedure PrintNum;
    begin
      WriteLn(Num);
    end;
    
    end.
    

    DllTestApp.dpr:

    program DLLTestApp;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils;
    
    // Links to the procedures in the DLL. Note that the DLL has to be
    // in the same folder, or located somewhere on the Windows PATH. If 
    // it can't be found, your app won't run.
    procedure AddToNum; external 'DLLSample.dll';
    procedure PrintNum; external 'DllSample.dll';
    
    
    begin
      PrintNum;   // Print initial value
      AddToNum;   // Add to it twice
      AddToNum;
      PrintNum;   // Print new value
      ReadLn;     // Wait for Enter key
    end.
    

    This outputs:

    0
    2
    

    in a console window and waits for you to hit Enter to close it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will take a string and pascal case it. The
I have a console application written in Free Pascal, that like most larger applications
I'm not that familiar with inno (or pascal scripting), but I am assuming what
Does anyone have a Delphi / Pascal example for calling the below OpenSSL functions...
I was looking for a Pascal equivalent for (for example) the php's substr function,
How can I share Objects across DLL's? Example: DLLA is loaded by Process A.
How can I print the apostrophe sign in Pascal using the writeln function? Example:
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want
Example: print max(chain_length(i) for i in xrange(1,10001)) This returns the maximum/biggest chain_length (an arbitrary
Example: $ objdump Logger.cpp.o -t 00000000 g F .text 00000000 .hidden __sti___10_Logger_cpp_0b2ae32b

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.