Pascal/Turbo Pascal - ayuda , longvariable no le encuentro de error al insertar

 
Vista:

ayuda , longvariable no le encuentro de error al insertar

Publicado por rodrigo (1 intervención) el 02/05/2014 11:13:04
necesito ayuda con el programa de long variable . esta primitiva no me anda y no se por que tengo que entregar el trabajo el martes y hace 2 dias q no le encuentro el error .para los q no entienden de que se trata . el insertar tiene q buscar un bloque donde tenga algo de espacio vacio donde entren esos datos q voy a agregar . si lo encuentra lo tiene q agregar a ese bloque y despues al archivo . si no lo encuentro debe . crear un bloque nuevo . copiarle los datos y agregarlo al final del archvo


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
procedure insertar(var pp: tPersonas; dni:string;nombre:string;apellido:string;fecha:string);
{Agrega una persona en el primer bloque que tenga espacio o, si no hay ninguno,
en un bloque nuevo al final del archivo}
Var
	tamregdni,tamregnombre,tamregapellido,tamregfecha:Byte;
   tamReg: Byte;
   libres: Word;
   disponibles: Integer;
   aux:string;
   n:integer;
Begin
 
 
seek(pp.espLibre,0);
tamReg:=Length(dni)+1+length(nombre)+1+length(apellido)+1+length(fecha)+1;
 
Repeat
Read(pp.espLibre, libres);
disponibles:=libres-Round((1-PorcCarga)*CapacBloque)
{bytes libres menos los que no se pueden usar para altas}
until eof(pp.espLibre) or (disponibles>=tamReg);
If tamReg>disponibles then
     begin
     {hay que agregar un nuevo bloque al final del archivo}
     pp.bloque.cantRegs:=0;
     libres:=CapacBloque;
     pp.iBloque:=1;
     Seek(pp.arch, FileSize(pp.arch))
     end
else Begin
 
     Seek(pp.arch, FilePos(pp.espLibre)-1); Read(pp.arch, pp.bloque);
 
     pp.iBloque:=CapacBloque-libres+1;
 
     Seek(pp.arch, FilePos(pp.espLibre)-1); seek(pp.espLibre, FilePos(pp.espLibre)-1)
     end;
 
tamregdni:=length(dni)+1;
 
Move(dni, pp.bloque.contenido[pp.iBloque], tamRegdni);
inc(pp.ibloque,tamregdni);
 
tamregnombre:=length(nombre)+1;
Move(nombre, pp.bloque.contenido[pp.iBloque], tamregnombre);
inc(pp.ibloque,tamregnombre);
 
tamregapellido:=length(apellido)+1;
Move(apellido, pp.bloque.contenido[pp.iBloque], tamregapellido);
inc(pp.ibloque,tamregapellido);
 
tamregfecha:=length(fecha)+1;
Move(fecha, pp.bloque.contenido[pp.iBloque], tamregfecha);
inc(pp.ibloque,tamregfecha);
 
 
Inc(pp.bloque.cantRegs);
Dec(libres,tamReg);
Write(pp.arch, pp.bloque);
 
Write(pp.espLibre, libres);
 
writeln('file pos ',filepos(pp.arch));
readln();
 
 
end;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

ayuda , longvariable no le encuentro de error al insertar

Publicado por Diego (98 intervenciones) el 02/05/2014 17:41:54
Para empezár hay que saber si el posicionamiento del primer seek es válido, ya que si el archivo libre no está abierto se producirá un error;
¿El error se genra durante la compila ción o la ejecución?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

ayuda , longvariable no le encuentro de error al insertar

Publicado por Diego (98 intervenciones) el 02/05/2014 18:46:41
Se me olvidó decirte que si el problema es en tiempo de ejecución y genera un error sería mejor que escribieras cual es el error así se podría saber donde buscar.
De todas formas te paso un link donde indican los errores que se generan en pascal; ya que en la prática que dan en la unlp solo están algunos.
http://www.freepascal.org/docs-html/user/userap4.html
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ayuda , longvariable no le encuentro de error al insertar

Publicado por ramon (2158 intervenciones) el 03/05/2014 12:16:57
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{Mira a ver si esto te ayuda en caso de que sean variables quita el registro y pon como variables}
 
program ejemplo;
  uses
     crt;
  type
     registro = record
           dni : longint;
        nombre : string[80];
      apellido : string[80];
         fecha : string[12];
       end;
 
   var
     f : file of registro;
     datos : registro;
     dd : longint;
 
 
    procedure guardaarchivo(d : registro);
    begin
        assign(f,'regdatos.dat');
     {$I-} reset(f); {$I+}
     if ioresult <> 0 then
     begin
        rewrite(f);
        seek(f,0);
        write(f,d);
        close(f);
     end
  else
     begin
        seek(f,filesize(f));
        write(f,d);
        close(f);
     end;
    end;
 
    procedure entradagatos;
    begin
       clrscr;
       writeln('  Entrada Datos ficha ');
       writeln;
       write('  Entre Numero DNI        : ');
       readln(datos.dni);
       write('  Entre Nombre            : ');
       readln(datos.nombre);
       write('  Entre Apellido          : ');
       readln(datos.apellido);
       write('  Entre Fecha dia/mes/a¤o : ');
       readln(datos.fecha);
       guardaarchivo(datos);
    end;
 
    procedure muestraregistro;
    var
      cont : longint;
      tecla : char;
    begin
        assign(f,'regdatos.dat');
     {$I-} reset(f); {$I+}
     if ioresult <> 0 then
     begin
        writeln('  Error Archivo No Encontrado Pulse Una Tecla');
        readkey;
     end
   else
      begin
         cont := 0;
      repeat
         seek(f,cont);
         read(f,datos);
         clrscr;
         writeln('   Num. DNI = ',datos.dni);
         writeln('   Nombre   = ',datos.nombre);
         writeln('   Apellido = ',datos.apellido);
         writeln('   Fecha    = ',datos.fecha);
         writeln;
         writeln('  Ver Alante A Tras [ ',chr(24),' ',chr(25),' ] Salir [ESC]');
       repeat
         tecla := readkey;
       until tecla in[#72,#80,#27];
       if tecla = #72 then
       begin
          cont := cont + 1;
          if cont > filesize(f) - 1 then
          cont := 0;
       end;
       if tecla = #80 then
       begin
          cont := cont - 1;
          if cont < 0 then
          cont := filesize(f) - 1;
       end;
      until tecla = #27;
      close(f);
      end;
    end;
 
  procedure buscarficha(n : longint);
  var
    bus : longint;
    encontrado : boolean;
  begin
     encontrado := false;
     assign(f,'regdatos.dat');
     {$I-} reset(f); {$I+}
     if ioresult <> 0 then
     begin
        writeln('  Error Archivo No Encontrado Pulse Una Tecla');
        readkey;
     end
   else
      begin
         for bus := 0 to filesize(f) - 1 do
         begin
            seek(f,bus);
            read(f,datos);
            if datos.dni = n then
            begin
               encontrado := true;
               break;
            end;
         end;
         if encontrado = true then
         begin
         clrscr;
         writeln('  Datos Del Numero ',n);
         writeln;
         writeln('   Num. DNI = ',datos.dni);
         writeln('   Nombre   = ',datos.nombre);
         writeln('   Apellido = ',datos.apellido);
         writeln('   Fecha    = ',datos.fecha);
         writeln;
         writeln('  Pulse Una Tecla ');
         readkey;
         end
      else
         begin
            clrscr;
            writeln('  Numero DNI No Encontrado');
            writeln('  Pulse Una Tecla ');
            readkey;
         end;
         close(f);
      end;
  end;
 
  procedure menu;
  var
    salir : boolean;
    tec : char;
   begin
      salir := false;
    repeat
        clrscr;
        writeln('  **** Menu Jeneras ****');
        writeln;
        writeln('  E = Entrada Fichas');
        writeln('  M = Mostrar Fichas');
        writeln('  B = Buscar Ficha');
        writeln('  S = Salir');
        writeln;
        writeln('  << Elija Opcion >>');
        repeat
            tec := upcase(readkey);
        until tec in['E','M','B','S'];
        clrscr;
   case tec of
 'E' : entradagatos;
 'M' : muestraregistro;
 'B' : begin
          writeln('  Busqueda Por DNI ');
          writeln;
          write('  Entre DNI A Buscar : ');
          readln(dd);
          buscarficha(dd);
       end;
 'S' : salir := true;
   end;
    until salir = true;
 end;
 
   begin
     menu;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar