Solved

Read Ini file from Compiled DLL

Posted on 2004-04-30
6
637 Views
Last Modified: 2011-10-03
Ok i am using Delphi 5
I have a ActiveX DLL project.

I need a DLL that inserts data into a SQLServer Database. this same DLL needs to work for various clients, which is where the ini file comes in. I can just change the connection data in the ini file and the dll should know where to connect and how.

In my DLL I have this code :

var F:TIniFile;
begin
  F := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'MyProject.ini');

  strUser := F.ReadString('Connection', 'Login', 'User');
  strPass := F.ReadString('Connection', 'Password', 'Pass');

  F.Free;

But its like the dll gets the values from the ini file when compiled.. and if i change the ini file afterwards he doesnt notice. that means he doesnt read from the ini file....

any sugestion on how i can accomplish what i need? if there is other ways in getting outside information to the dll that could also answer this question.

Thanks

Denis
0
Comment
Question by:Canadenis
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10958982

   From the client send the FileName to the DLL... and in the DLL remove this ExtractFilePath..
0
 
LVL 17

Expert Comment

by:mokule
ID: 10958998

It can't read in compile time.

I doubt whether ParamStr is valid in dll.

Maybe Your ini file is not found or You have invalid section or ident and the default values are used.
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 125 total points
ID: 10959009

   I think I know where is the problem. I had similar problem in the past. When you compile the DLL file - ParamStr(0) is the DLL file itself. But when you include it in client ParamStr(0) is already the client.

   ParamStr(0), Self, Application.ExeName are "transparent" variables
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:mokule
ID: 10959023
BTW
Having login and password in an ini file seems not the best idea.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10959727

Denis,

Perhaps while your at it, you may wish to either cleanup/accept/close the following question you have open:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20873511.html

Regards,
Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10961308
It all depends on which path you are after. If it is the calling proces, then use the ExePath listed below. If it is your dll's path that your require, then use the LibraryPath function

Regards, and thanks...
Russell

function ExePath: String;
var  lpBuffer:   Array [0..MAX_PATH] of Char;
begin

  // This will always return the exe's path. For libraries, it will return the
  // path for the hosting process
  GetModuleFilename(0, lpBuffer, SizeOf(MAX_PATH));
  result:=ExcludeTrailingBackslash(ExtractFilePath(lpBuffer));

end;

function LibraryPath: String;
var  lpBuffer:   Array [0..MAX_PATH] of Char;
begin

  // Return the dll's path
  if IsLibrary then
  begin
     GetModuleFilename(hInstance, lpBuffer, SizeOf(MAX_PATH));
     result:=ExcludeTrailingBackslash(ExtractFilePath(lpBuffer));
  end
  else
     // Not a library
     result:='';

end;
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

8 Experts available now in Live!

Get 1:1 Help Now