ini file reading

Hello all

I have an application that needs to read an ini file.

It needs to compare a number (a count) from an SQL statement to a number stored in the ini file. The number in the ini file will be stored next to an identifier such as  'client=3' and if possible i want to set how many places along the string the number will be in the ini file eg 'client=12*3*456' so the number i want for comparrison is still number 3

any help appreciated
Paul-BrooksAsked:
Who is Participating?
 
David_WardConnect With a Mentor Commented:
uses TiniFiles;

Function GetMyINI_Data(IniFname,SectionName,KeyName: String): Integer;
var
  ThisINI:    TIniFile;
  s1:           String;
begin
  result:=-1;
  ThisINI:=TiniFile.Create(IniFname);

  try
    s1:=ThisINI.ReadString(SectionName,KeyName,'-1');
    if s1<>'-1'  then
      begin
          result:=StrToIntDef(s1,-2);

          // decode "whatever" you did to encode the number before you saved it in the INI file

      end;

   
  finally
    ThisINI.free;
   
  end;

end;
0
 
DragonSlayerCommented:
i don't get you :-(
0
 
Paul-BrooksAuthor Commented:
OK

If i have an ini file that contains the line client=3, how do i read that in my delphi app and as a secondary question can i hide that number(the 3) in a string and count the places to find it as a sort of encryption

Cheers
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
David_WardCommented:
// decode "whatever" you did to encode the number before you saved it in the INI file
// i.e.
result:=(result div 12) div 456;
0
 
David_WardCommented:
>>if possible i want to set how many places along the string the number will be in the ini file eg 'client=12*3*456' so the number i want for comparrison is still number 3

I really would not bother with something like this, I would just mathematically alter the number according to -some- formula

Some.INI
[Some.Section]
Client=16416

// 16416/12/456=3


0
 
atul_parmarCommented:
Or to decode the hidden number from string you can use
  s := '12*3*456';
  s := Copy(s, pos('*', s)+1, length(s));
  s := copy(s, 1, pos('*', s)-1);
0
 
Paul-BrooksAuthor Commented:
David

I am using Delphi 2005 and when i put the TiniFiles in the uses, the project will not compile with a cant resolve unit name error

0
 
David_WardCommented:
yea, sorry, the unit name is;

IniFiles

not "T"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.