como não adicionar String repetidos numa Array ?

Delphi

12/03/2003

oi Amigo
tenhu uma Array [1..10] Estou adcionando valores de uma tabela nele
Duvida:
como não adicionar String´s repedidos no array
alguem sabe ??
Estou usando assim:

[b:f2997b93d5]Var at:array[1..10] of string;
i:Integer;
Begin
While not tabela.eof do
Begin
At[i]:=TbAnexarTURMAS.value;
End;
for i := 1 to nt do
QrlTurma.Caption:=QrlTurma.Caption+trim(At[i])+´, ´;
End;[/b:f2997b93d5]
Por favor me ajude ?


Anonymous

Anonymous

Curtidas 0

Respostas

Anonymous

Anonymous

12/03/2003

Tem next no While ok...
por favor ajude me ..


GOSTEI 0
Marcelo Saviski

Marcelo Saviski

12/03/2003

[b:c589c4dd0a]function[/b:c589c4dd0a] TForm1.testaarray(vetorarray : [b:c589c4dd0a]array of [/b:c589c4dd0a]string, texto : string): boolean;
[b:c589c4dd0a]var[/b:c589c4dd0a]
i:integer;
[b:c589c4dd0a]begin
for[/b:c589c4dd0a] i := low(vetorarray) to high(vetorarray) [b:c589c4dd0a]do
begin
if[/b:c589c4dd0a] vetorarray[i] = texto [b:c589c4dd0a]then
begin[/b:c589c4dd0a]
result := true;
exit;
[b:c589c4dd0a] end;
end;
[/b:c589c4dd0a]result := false
[b:c589c4dd0a]end;[/b:c589c4dd0a]


Chame ela assim

[b:c589c4dd0a]Var [/b:c589c4dd0a]at:array[1..10] [b:c589c4dd0a]of string; [/b:c589c4dd0a]i:Integer;
[b:c589c4dd0a]Begin
While not [/b:c589c4dd0a]tabela.eof [b:c589c4dd0a]do [/b:c589c4dd0a]Begin
[b:c589c4dd0a]if not[/b:c589c4dd0a] testaarray(at, TbAnexarTURMAS.value) [b:c589c4dd0a]then[/b:c589c4dd0a]At[i]:=TbAnexarTURMAS.value;
[b:c589c4dd0a]End; [/b:c589c4dd0a]
[b:c589c4dd0a]for[/b:c589c4dd0a] i := 1[b:c589c4dd0a] to[/b:c589c4dd0a] nt [b:c589c4dd0a]do [/b:c589c4dd0a]
QrlTurma.Caption:=QrlTurma.Caption+trim(At[i])+´, ´;
[b:c589c4dd0a]End; [/b:c589c4dd0a]
[img:c589c4dd0a]http://www.apriori.com.br/cgi/forum/images/smiles/icon_cool.gif[/img:c589c4dd0a][img:c589c4dd0a]http://www.apriori.com.br/cgi/forum/images/smiles/icon_rolleyes.gif[/img:c589c4dd0a]


GOSTEI 0
Anonymous

Anonymous

12/03/2003

Oi Amigo eu fico grata mais não sei como declarar esssa Function
Vc pode me ajudar ???


GOSTEI 0
Marcelo Saviski

Marcelo Saviski

12/03/2003

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
function TForm1.testaarray(vetorarray : array of string, texto : string):boolean
[color=blue:75c896cd3e]//tem que declara ela no código do seu form como está aqui[/color:75c896cd3e]
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

[color=blue:75c896cd3e]//copie e cole a função abaixo, cole depois de {$R *.DFM}[/color:75c896cd3e]
function TForm1.testaarray(vetorarray : array of string, texto : string):boolean;
var
i:integer;
begin
for i := low(vetorarray) to high(vetorarray) do
begin
if vetorarray[i] = texto then
begin
result := true;
exit;
end;
end;
result := false
end;
[img:75c896cd3e]http://www.apriori.com.br/cgi/forum/images/smiles/icon_cool.gif[/img:75c896cd3e][img:75c896cd3e]http://www.apriori.com.br/cgi/forum/images/smiles/icon_rolleyes.gif[/img:75c896cd3e]


GOSTEI 0
POSTAR