Einzelnen Beitrag anzeigen

Benutzerbild von Deltachaos
Deltachaos

Registriert seit: 20. Feb 2008
Ort: Berlin
195 Beiträge
 
Delphi 7 Personal
 
#1

Explode aus CodeLib. - Inkompatible Typen.

  Alt 18. Aug 2009, 12:28
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;
Maximilian Ruta
Ich weiß mein Deutsch ist ! Bei Fragen: ich bin fast immer im Mumble
Server: cubexsports.de
Port: 64738
  Mit Zitat antworten Zitat