Read Ini from a site

4

I want to read the ini file of a website, but I can not. I tried this way:

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

But it is not working. How should it 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 it did not, I did not see any difference between mine and yours. The client, it worked, being the same thing.

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

    
asked by anonymous 17.10.2014 / 14:50

1 answer

4

The Create of TIniFile method requires an existing file on disk. So do not try to pass it to you what you are getting with the IdHTTP component without first saving it to disk and then opening it with 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.

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

    
17.10.2014 / 15:03