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

Read Ini file from Compiled DLL

Posted on 2004-04-30
6
650 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
control image tags in a string ? 12 142
Dev express lookupcombo 3 35
MS Access from Delphi 31 60
Firemonkey BASS_Init into a thread 17 31
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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