Link to home
Start Free TrialLog in
Avatar of Professor
Professor

asked on

Win32 API

i need to use the following win32 api functions in delphi:

GetPrivateProfileSection,
GetPrivateProfileString,
WritePrivateProfileSection and
WritePrivateProfileString

for reading from and writing to ini files.

I just don't seem to be able to figure out how to actually make delphi use the functions...

Can someone help please?
Thanks in advance
Avatar of Professor
Professor

ASKER

yeah ;) *lol*
ASKER CERTIFIED SOLUTION
Avatar of gmayo
gmayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Easy...

var
    TheValue: Array[0..MAX_PATH] of Char;
begin
    // Get some file path from 'TheIniFile.ini' in your applications directory.
    GetPrivateProfileString('Paths', 'FilePath1', nil, @TheValue, MAX_PATH, PChar(ExtractFilePath(ParamStr(0))+'TheIniFile.ini'));
    // Write your own filepath to FilePath2 value
    WritePrivateProfileString('Paths', 'FilePath2', PChar(ParamStr(0)), PChar(ExtractFilePath(ParamStr(0))+'TheIniFile.ini'));
end;

I wrote this code from memory so if something is wrong don't hesitate to tell me (Should work perfectly though)
@gmayo:

This is about the basics of what I'm trying to do:

const cfgFile = 'ext-pisg.conf';

procedure tConfig.Load;
var cfgIni : TIniFile;
    str : TStrings;

begin
 cfgIni.Create(cfgFile);
 MessageDlg(cfgIni.FileName, mtInformation,
      [mbOk], 0);


end;

but whenever I call the cfgIni.Create(cfgFile); i get a Stack Overflow. Do you know why this happens?
You're creating it wrong. Use:
 cfgIni := TIniFile.Create(cfgFile);
instead of:
 cfgIni.Create(cfgFile);

That should work!

Geoff M.