Read Ini from a website

Asked

Viewed 179 times

4

I want to read the ini file of a site, but I’m not getting.
I tried so:

inicheck := 'http://pokestage.ddns.net/patch/CHECK.INI';
conf2 := TIniFile.Create(IdHTTP3.Get(inicheck));
version2 := conf2.ReadString('CONFIG', 'TVERSION', '');

But it’s not working.
How it should be done?

I tested it like this:

var
  conf2 : TIniFile;
  version2 : string;
  inicheck : string;
  path : string;
  tempfile : TFileStream;
begin
  path := extractFilepath(application.exename);
  inicheck := 'http://pokestage.ddns.net/patch/CHECK.INI';
  tempfile := TFileStream.Create('SCHECK.INI', fmCreate);
  try
    tempfile.Position:=0;
    IdHTTP3.Get(inicheck, tempfile);
    tempfile.Free;
    conf2 := TIniFile.Create(path+'\SCHECK.INI');
    version2 := conf2.ReadString('CONFIG', 'TVERSION', '');
  finally
    conf2.Free;
  end;
  ShowMessage('Client '+version);
  ShowMessage('Servidor '+version2)

And I didn’t, I don’t see the difference between yours and mine. The client, worked, being the same thing.

Edit: I got it, I was putting tempfile.free; in the wrong place, you have to close before creating ini. I already set in the example.

  • 1

    Yes, but it worked. rs.

1 answer

4


The method Create of TIniFile requires an existing disk file. So it doesn’t work trying to pass to it what you are getting with the component IdHTTP without first saving it to disk to then open with the TIniFile.

So try something like:

var
  fileIni: TIniFile;
  response: TFileStream;
  version: string;
begin
  response := TFileStream.Create(ExtractFilePath(Application.ExeName) + 'iniFile.ini', fmCreate);
  try
    response.Position := 0;
    IdHTTP.Get('http://pokestage.ddns.net/patch/CHECK.INI', response);
  finally
    response.Free;
  end;

  fileIni := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'iniFile.ini');
  try
    version := fileIni.ReadString('CONFIG', 'TVERSION', '');
    showMessage(version);
  finally
    fileIni.Free;
  end;

  // faça o que precisa com a variável "version"
end;

I tested this code with your url and it worked.

Teste

Detail you are using 'CONFIG' and 'TVERSION' to read the value, but in your file is 'CONF' and 'VERSION'.

  • Returned this error: variable Might not have been initialized

  • It hasn’t worked yet, it’s Delphi 7, Indy 10, returns no error, just doesn’t take the value.

  • Look at Dit, I’m doing pretty much the same, but you’re not going

Browser other questions tagged

You are not signed in. Login or sign up in order to post.