Questo è il codice corretto....
Io voglio leggere una stringa, che arriva dalla seriale,e spezzarla dove si hanno i separatori (che nel mio caso sono virgole), fatto ciò voglio estrarre solo i campi che mi interessano.
io questo prima di tentare di farlo su stringhe che arrivavano dallo strumento collegato alla seriale lo facevo con dei file che acquisivo con un'altro programma (ora ho l'esigenza del real time, prima no!)...
Spero che possiate essermi d'aiuto...
Grazie...
[code]
function str2real(s:string):real;
var x:real;
c:integer;
begin
val(s,x,c);
str2real:=x;
end;
function real2str(x:real;c,d:integer):string;
var st:string;
begin
str(x:c:d,st);
real2str:=st;
end;
function str2int(s:string):integer;
var x:integer;
c:integer;
begin
val(s,x,c);
str2int:=x;
end;
function int2str(x:integer;c:integer):string;
var st:string;
begin
str(x:c,st);
int2str:=st;
end;
function ParseString(stringa,separatore:string):TStringVect or;
var i,k:integer;
st:string;
tmp:TStringVector;
begin
st:=stringa;
i:=0;
setlength(tmp,i);
while length(st)>0 do
begin
k:=pos(separatore,st);
if k>0 then
begin
i:=i+1;
setlength(tmp,i);
tmp[i-1]:=leftstr(st,k-1);
st:=rightstr(st,length(st)-k);
end
else
begin
i:=i+1;
setlength(tmp,i);
tmp[i-1]:=st;
st:='';
end;
end;
ParseString:=tmp;
end;
[\code]
![]()