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
TCustomParameters = record
Header: array[0..3] of char;
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
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!