Solved

Read Ini file from Compiled DLL

Posted on 2004-04-30
6
667 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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