Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
Delphi 7 Enterprise
|
AW: AVR Bascom Funktion in Delphi???
15. Aug 2010, 18:04
Was ist so schwer daran, sowas selber zu schreiben?
Delphi-Quellcode:
function Lookup(offset:integer; DataIN:string):string;
type
TStatus = (sNone, sKommentar, sData);
var
i, dataindex:integer;
Status:TStatus;
stop:boolean;
begin
i:=1;
Status:=sNone;
dataindex:=0;
Result:='';
stop:=false;
while (i < length(dataIN)) and not stop do begin
if dataIN[i] = '''' then begin
if Status = sData then begin
stop:=(dataindex = offset);
inc(dataindex);
end;
Status:=sKommentar;
end
else if dataIN[i] = #10 then begin
if Status = sData then begin
stop:=(dataindex = offset);
inc(dataindex);
end;
Status:=sNone;
end
else if (Status = sNone) and (copy(dataIN, i, 5) = 'Data ') then begin
Status:=sData;
Result:='';
inc(i, 4);
end
else if Status = sData then begin
if dataIN[i] = ',' then begin
stop:=(dataindex = offset);
inc(dataindex);
if not stop then
Result:='';
end
else Result:=Result + dataIN[i];
end;
inc(i);
end;
Result:=trim(Result);
end;
Aufruf...
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
Liste:TStringList;
begin
Liste:=TStringList.Create;
try
Liste.Append('''Data 25%');
Liste.Append('Data 1%,25%,3%');
Liste.Append('Data 100%,2%');
Liste.Append('Data 100%,26%,64%,34%');
ShowMessage('>' + Lookup(0, Liste.Text) + '<');
finally
Liste.free;
end;
end;
Geändert von omata (15. Aug 2010 um 18:27 Uhr)
|
|
Zitat
|