![]() |
Explode aus CodeLib. - Inkompatible Typen.
Ich habe ein Array of string als Ziel definiert und obwohl Explode als rückgabe doch auch ein array of String hat bekomm ich die meldung inkompatible typen.
Warum das?
Delphi-Quellcode:
type TSTringdynarray = array of String;
function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray; var SepLen: Integer; F, P: PChar; ALen, Index: Integer; begin SetLength(Result, 0); if (S = '') or (Limit < 0) then Exit; if Separator = '' then begin SetLength(Result, 1); Result[0] := S; Exit; end; SepLen := Length(Separator); ALen := Limit; SetLength(Result, ALen); Index := 0; P := PChar(S); while P^ <> #0 do begin F := P; P := AnsiStrPos(P, PChar(Separator)); if (P = nil) or ((Limit > 0) and (Index = Limit - 1)) then P := StrEnd(F); if Index >= ALen then begin if aLen=0 then aLen := 10 else aLen := aLen * 2; SetLength(Result, ALen); end; SetString(Result[Index], F, P - F); Inc(Index); if P^ <> #0 then Inc(P, SepLen); end; if Index < ALen then SetLength(Result, Index); end; procedure TForm1.Button1Click(Sender: TObject); var ar: array of string; begin ar := explode('|', 'bbb|ccc|ddd') end; |
Re: Explode aus CodeLib. - Inkompatible Typen.
das liegt daran, daß zwar der Aufbau der Typen zwar gleich ist, aber dennoch die Typen nicht identisch sind!
Delphi ist da sehr streng
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var ar: TStringDynArray; begin ar := explode('|', 'bbb|ccc|ddd') end; |
Re: Explode aus CodeLib. - Inkompatible Typen.
In welcher Zeile tritt der Fehler auf?
|
Re: Explode aus CodeLib. - Inkompatible Typen.
Wozu hast du es neu deklariert?
TStringDynArray ist in types bereits vorhanden. Binde types einfach mal ein. |
Re: Explode aus CodeLib. - Inkompatible Typen.
thx :)
nur wie convertiere ich das wieder? z.b. wenn ich den inhalt in eine listbox übertragen will? oder muss ich das überhaupt? |
Re: Explode aus CodeLib. - Inkompatible Typen.
sollte in etwa so funktionieren:
Delphi-Quellcode:
Grüße
for i:=low(ar) to high(ar) do
listbox.items.add(ar[i]); Klaus |
Re: Explode aus CodeLib. - Inkompatible Typen.
Klaus war zwar schneller, aber ich poste meine gerade erstellte Routine trotzdem.
Delphi-Quellcode:
[edit] Eine Zeile verrutscht [/edit]
procedure ArrayToTStrings(const Arr: TStringDynArray; const s: TStrings);
var i: integer; begin s.BeginUpdate; try s.Clear; for I := Low(arr) to High(Arr) do s.Add(Arr[i]); finally s.EndUpdate; end; end; |
Re: Explode aus CodeLib. - Inkompatible Typen.
ok also muss ich das array durchgehen
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz