Ver Mensaje Individual
  #3  
Antiguo 11-01-2006
Avatar de delphi.com.ar
delphi.com.ar delphi.com.ar is offline
Federico Firenze
 
Registrado: may 2003
Ubicación: Buenos Aires, Argentina *
Posts: 5.932
Reputación: 27
delphi.com.ar Va por buen camino
Yo alguna vez lo hice, prefiero reservarme para que , y creo que lo comenté en el foro alguna vez, pero no lo he encotrado.
El problema principal es que Windows cuando crea un proceso marca el archivo ejecutado como solo lectura, deniega la escritura en el mismo. O sea que solo podrás modificar los datos de un archivo que no este en uso, si mal no recuerdo había alguna rutina perdida en la red que hacía algunos malabares para permitirlo. Creo que las pruebas que hice al respecto fueron poco satisfactorioas.
Bueno, si te sirve que un programa cree una copia de si mismo con algunos estos datos, o que modifique otra compia del programa que si se podrá autoleer, esto que te he escrito te tiene que funcionar:
Código Delphi [-]
 
type
  { Plantilla de la información de configuración }
  TCustomParameters = record
    Header: array[0..3] of char; {Los PE Executables normalmente terminan en #0 el header es una marca extra}
    Value1: Integer;
    Value2: Integer;
    Value3: Integer;
    Value4: Integer;
  end;

const
  CP_HEADER = 'H'#23#25;

var
  Parameters: TCustomParameters;

procedure ReadParameters(AFileName: TFileName);
begin
  with TFileStream.Create(AFileName, fmOpenRead + fmShareDenyNone) do
    try
      Seek(-SizeOf(TCustomParameters), soEnd);
      ReadBuffer(Parameters, SizeOf(TCustomParameters));
    finally
      Free;
    end;
end;

procedure WriteParameters(AFileName: TFileName; ARecordExists: Boolean);
begin
  with TFileStream.Create(AFileName, fmOpenWrite + fmShareDenyNone) do
    try
      if ARecordExists then
        Seek(-SizeOf(TCustomParameters), soEnd)
      else
        Seek(0, soEnd);

      WriteBuffer(Parameters, SizeOf(TCustomParameters));
    finally
      Free;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ReadParameters(ParamStr(0));

  with Parameters do
  begin
    Edit1.Text := IntToStr(Value1);
    Edit2.Text := IntToStr(Value2);
    Edit3.Text := IntToStr(Value3);
    Edit4.Text := IntToStr(Value4);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
  begin
    {Lee anteriormente para fijase si ya se había agregado la información al final del archivo}
    ReadParameters(SaveDialog1.FileName);

    with Parameters do
    begin
      Header := CP_HEADER;
      Value1 := StrToIntDef(Edit1.Text, 0);
      Value2 := StrToIntDef(Edit2.Text, 0);
      Value3 := StrToIntDef(Edit3.Text, 0);
      Value4 := StrToIntDef(Edit4.Text, 0);
    end;
    WriteParameters(SaveDialog1.FileName, Parameters.Header <> CP_HEADER);
  end;
end;

Saludos!
__________________
delphi.com.ar

Dedique el tiempo suficiente para formular su pregunta si pretende que alguien dedique su tiempo en contestarla.
Responder Con Cita