Jump to content
Ian Branch

Read a .ini file in the project file??

Recommended Posts

Hi Team,

I have this code in the project file:

  // Create or open the DBW.ini file
  oDBWIni := TIniFile.Create('E:\DBiWorkflow\DBW.ini');
  try
    // Read the delimited IP addresses from the 'DBiDashboard' section with 'IPAddresses' identifier
    sAllowedIPs := oDBWIni.ReadString('DBiDashboard', 'IPAddresses', '');
  finally
    // Free the DBWIni object to release resources
    oDBWIni.Free;
    //
  end;
  //
  ShowMessage(sAllowedIPs);
  //

oDBWIni is declared as a TIniFile in the Var.

System.IniFiles is in the uses clause.

The file is there, the section is there, the identifier is there and there are valid IPs there.

But, sAllowedIPs shows nothing. 😞

What have I missed please?

 

Regards & TIA,

Ian

Share this post


Link to post
12 minutes ago, Ian Branch said:

What have I missed please?

Showing the actual content of the DBW.ini file located in E:\DBiWorkflow. Best attach the complete file so we can scan for suspicious characters.

Share this post


Link to post
Posted (edited)

This is the relevant section.

Quote

[DBiDashboard]
IPAddresses=27.32.138.205,127.0.0.1,255.255.255.255

I can't show the rest of the ini content as there is confidential information in it.

 

In another App, albeit in the mainform, I access the data like this:

procedure TMainForm.LoadIPMemoFromIni;
var
  DelimitedString: string;
  LineList: TStringList;
begin
  LineList := TStringList.Create;
  try
    DelimitedString := DBWIni.ReadString('DBiDashboard', 'IPAddresses', '');
    if DelimitedString <> '' then
    begin
      LineList.CommaText := DelimitedString;
      IPMemo.Lines.Assign(LineList);
    end;
  finally
    LineList.Free;
  end;
end;

And it works fine.

Here, DBWIni is a TIni component.

Edited by Ian Branch

Share this post


Link to post
3 minutes ago, Ian Branch said:

I can't show the rest of the ini content as there is confidential information in it.

I've copied IPADresses you posted and using the i.ReadString('DBiDashboard', 'IPAddresses', '') cannot reproduce your problem. 

Share this post


Link to post

Oh My!  Found it.

I really do need to get my eyes rechecked.

It wasn't DBWIni.ini, it was DBiWIni.ini.

All good now.

Thank you for your inputs and apologies for any inconvenience.

 

Ian

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×