Hola kirios.
Ahora creo que entendí lo que buscas.
A ver... tenés un archivo de texto con el nombre de un objeto y un valor separados por un ';' . Supongamos que se llame
Archivo.txt y contenga lo siguiente:
Código:
cama;1
mesa;2
silla;3
vaso;4
plato;5
banco;6
cuchillo;7
tenedor;8
cuchara;9
fuente;10
Entonces sería mucho más fácil hacerlo usando
TStrings :
Código Delphi
[-]
var
TS: TStrings;
procedure TForm1.FormCreate(Sender: TObject);
var
i,c: Integer;
begin
TS:= TStringList.Create;
TS.LoadFromFile('C:\Archivo.txt'); c:=0;
for i:= 0 to ComponentCount-1 do
if Components[i] is TCheckBox then
begin
TCheckBox(Components[i]).Caption:= Copy(TS[c],1,Pos(';',TS[c])-1); TCheckBox(Components[i]).Tag:= c; Inc(c);
end;
end;
function TForm1.preciobar: Double;
var
i,c:integer;
s: string;
begin
Result:= 0;
c:=0;
for i:= 0 to ComponentCount - 1 do
if Components[i] is TCheckBox then
if TCheckBox(Components[i]).Checked then
begin
s:= TS[TCheckBox(Components[i]).Tag]; Result:= Result + StrToFloat(Copy(s,Pos(';',s)+1, MaxInt)); Inc(c);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:= FloatToStr(preciobar);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
TS.Free;
end;
Por supuesto tendrás que tener tantos CheckBoxs como datos haya en el archivo...
Saludos.