Função para retornar um vetor String
Galera como faço para declarar uma Função para retornar um vetor String?
Ex.:
exemplo do meu fonte, eu sei que esta errado...
como faço isso....
function Tfrm_Princ.TiraPontoVirgula(Valor: string): array; <========
var i,x:integer;
aux: String;
v : array[1..6]: string;
begin
aux:=´´;
for x:= 1 to 6 do
begin
for i:= 1 to length(valor) do
begin
if valor[i] <> ´;´ then
begin
aux := aux + valor[i];
end
else
begin
v[1]:= aux;
aux:= ´´;
end;
end;
end;
Result := v; ******** aki to querendo retornar um vetor com 6 posicoes strings
end;
Ex.:
exemplo do meu fonte, eu sei que esta errado...
como faço isso....
function Tfrm_Princ.TiraPontoVirgula(Valor: string): array; <========
var i,x:integer;
aux: String;
v : array[1..6]: string;
begin
aux:=´´;
for x:= 1 to 6 do
begin
for i:= 1 to length(valor) do
begin
if valor[i] <> ´;´ then
begin
aux := aux + valor[i];
end
else
begin
v[1]:= aux;
aux:= ´´;
end;
end;
end;
Result := v; ******** aki to querendo retornar um vetor com 6 posicoes strings
end;
Guigosnet
Curtidas 0
Respostas
Emerson Nascimento
02/07/2008
respondendo sua pergunta...
mas eu trocaria tudo isso por:
type
TRetorno = array of string;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
function TiraPontoVirgula(Valor: string): TRetorno;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.TiraPontoVirgula(Valor: string): TRetorno;
var
i,x: integer;
aux: String;
v: TRetorno;
vParam: string;
begin
aux := ´´;
vParam := Valor;
while vParam <> ´´ do
begin
SetLength(v, Length(v)+1);
i := pos(´;´, vParam);
if i > 0 then
begin
v[High(v)] := Copy(vParam, 1, i-1);
Delete(vParam, 1, i);
end
else
begin
v[High(v)] := vParam;
vParam := ´´;
end;
end;
Result := v;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Retorno: TRetorno;
i: integer;
begin
Memo1.Clear;
Retorno := TiraPontoVirgula(Edit1.Text);
for i := Low(Retorno) to High(Retorno) do
Memo1.Lines.Add(Retorno[i]);
end;
mas eu trocaria tudo isso por:
procedure TForm1.Button1Click(Sender: TObject); var Lista: TStringList; begin Memo1.Clear; Lista := TStringList.Create; Lista.Delimiter := ´;´; Lista.DelimitedText := Edit1.Text; Memo1.Lines.AddStrings(Lista); end;
GOSTEI 0