Manejo de ID con archivos
Publicado por Ignacio (1 intervención) el 20/07/2017 16:10:51
Hola gente, mi primera vez en este foro y vi que responden muy bien las consultas. Estoy aprendiendo algo de Pascal para la uni y tengo que hacer un ABM de productos, y en la parte de Carga de productos quiero que el ID del producto se genere automaticamente sin pedirselo al usuario, pero no se como hacer que busque el ultimo producto cargado y use el id+1. Tengo hecho esto ( estuve probando cosas en PantallaCarga para ver si funcionaba pero nada):
EDITE AL PRINCIPIO EN TYPE ME FALTO PASAR EL RECORD. PERDON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
program Practica;
uses crt;
type TRegistro = record
idProducto:integer;
nombreProducto:string;
precioProducto:real;
activoProducto:boolean;
end;
var teclaInicio:char;
Productos:TRegistro;
AProductos: file of Tregistro;
procedure PantallaInicio;
begin
ClrScr;
writeln(' ADMINISTRADOR DE PRODUCTOS ');
writeln('Ingrese la opcion que desea realizar');
writeln('1 - CARGA PRODUCTO');
writeln('2 - MODIFICAR PRODUCTO');
writeln('3 - ELIMINAR PRODUCTO');
writeln('4 - BUSCAR PRODUCTO');
writeln('5 - SALIR');
end;
procedure PantallaCarga;
var idUltPro:integer;
begin
reset(AProductos);
while not EoF (Aproductos) do
begin
read(AProductos, Productos);
idUltPro:=Productos.idProducto;
end;
seek(AProductos, Filesize(AProductos));
ClrScr;
writeln(' CARGA DE PRODUCTOS');
writeln('Producto con ID: ', idUltPro+1);
writeln('Nombre producto: ');
readln(Productos.nombreProducto);
writeln('Precio producto: ');
readln(Productos.precioProducto);
write(AProductos, Productos);
writeln(' PRODUCTO CARGADO');
end;
BEGIN
assign(AProductos, 'C:\Users\Jorge\Desktop\AProductos.dat');
{$I-}
Reset(AProductos);
{$I+}
if IoResult<>0 then
Rewrite(AProductos);
repeat
ClrScr;
PantallaInicio;
teclaInicio:=Readkey;
case teclaInicio of
'1':
begin
PantallaCarga;
Readkey;
end;
end;
until teclaInicio = '5';
END.
EDITE AL PRINCIPIO EN TYPE ME FALTO PASAR EL RECORD. PERDON
Valora esta pregunta


0