Solved

Read Ini file from Compiled DLL

Posted on 2004-04-30
6
642 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
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.

 
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

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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, f…

867 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

16 Experts available now in Live!

Get 1:1 Help Now