не проверял пока но вроде должно работать
винт не будет сильно дергать? если это вызывается около 200 раз в минуту
случайная строка
Код:
function TMyThread.random1(Myfile: string; nomer: integer): string;
var
f:TextFile;
n,r: integer;
begin
n:=0;
AssignFile(f,MyFile+'.txt');
Reset(f);
While not EOF(f) do
begin
inc(n);
end;
CloseFile(f);
r:=random(n)+1;
Reset(f);
While not EOF(f) do
begin
inc(n);
if n=r then
begin
readln(f,result);
break;
end;
end;
end;
с разделителем '#'
Код:
function TMyThread.random2(Myfile: string; nomer: integer): string;
var
f:TextFile;
buf: string;
n,r: integer;
begin
n:=-1;
AssignFile(f,MyFile+'.txt');
Reset(f);
While not EOF(f) do
begin
readln(f,buf);
if trim(buf)='#' then inc(n);
end;
CloseFile(f);
r:=random(n)+1;
n:=0;
Reset(f);
While not EOF(f) do
begin
readln(f,buf);
if n=r then
begin
if trim(buf)='#' then inc(n);
if n=r then result:=result+#13#10+buf
else break;
end
else if trim(buf)='#' then inc(n);
end;
end;