Solved

Read Ini file from Compiled DLL

Posted on 2004-04-30
6
644 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

15 Experts available now in Live!

Get 1:1 Help Now