Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   read string from offset - upgrade needed (https://www.clubdelphi.com/foros/showthread.php?t=47806)

scriptors 07-09-2007 14:51:14

read string from offset - upgrade needed
 
Código Delphi [-]
 
Function TMainForm.ReadFromOffset(const RAWFile: String; OffsetI: integer;BlockLength:Integer): string;
var
  RAW: file;
  BytesRead: integer;
  RAWData: array[1..5000] of char;
  I: integer;
  c: pointer;
  return: string;
  begin
  BytesRead := -1;
  return := '';
  AssignFile(RAW, RAWFile);
  Reset(RAW,1);
  for I := 0 to OffSetI - 1 do
    Blockread(RAW,c,1);
  BlockRead(RAW,RAWData,BlockLength,BytesRead);
  for I := 1 to BlockLength do
    return := return + RAWData[i];
  ReadFromOffset := return;
  CloseFile(RAW);
  end;

I use this for read byte from datafile at offset and have result one string
this work but are really time expensive if i need to meke more search :(

I think because it search all file for go to 'offset'

someone can upgrade this routine ?

basti 07-09-2007 15:08:19

He leído en otro mensaje que entiendes el castellano escrito, así que te respondo en castellano:

En la función hay un error, debería retornar el valor de 'return'.

Por otro lado, puedes usar la función seek para ir a una posición del archivo directamente:


Código Delphi [-]
Function TMainForm.ReadFromOffset(const RAWFile: String; OffsetI: integer;BlockLength:Integer): string;
var
  RAW: file;
  BytesRead: integer;
  RAWData: array[1..5000] of char;
  I: integer;
  c: pointer;
  return: string;
begin
  BytesRead := -1;
  return := '';
  AssignFile(RAW, RAWFile);
  Reset(RAW,1);
  Seek(RAW, OffsetI - 1);

  BlockRead(RAW,RAWData,BlockLength,BytesRead);

  for I := 1 to BlockLength do
    return := return + RAWData[i];

  ReadFromOffset := return;
  CloseFile(RAW);
  result := return;
end;

scriptors 07-09-2007 15:35:32

encantado :D:D

from 25 sec -> to 1 sec :D
correct little 'bug'

Código Delphi [-]
 
Function TMainForm.ReadFromOffset(const RAWFile: String; OffsetI: integer;BlockLength:Integer): string;
var
  RAW: file;
  BytesRead: integer;
  RAWData: array[1..5000] of char;
  I: integer;
  c: pointer;
  return: string;
begin
  BytesRead := -1;
  return := '';
  AssignFile(RAW, RAWFile);
  Reset(RAW,1);
  Seek(RAW, OffsetI); // - 1 NOT necessary :D
 
  BlockRead(RAW,RAWData,BlockLength,BytesRead);
 
  for I := 1 to BlockLength do
    return := return + RAWData[i];
 
  ReadFromOffset := return;
  CloseFile(RAW);
  result := return;
end;


La franja horaria es GMT +2. Ahora son las 21:22:23.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi