Fórum como não adicionar String repetidos numa Array ? #144751
12/03/2003
0
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
Curtir tópico
+ 0Posts
12/03/2003
Anonymous
por favor ajude me ..
Gostei + 0
12/03/2003
Marcelo Saviski
[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_eek.gif[/img: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
12/03/2003
Anonymous
Vc pode me ajudar ???
Gostei + 0
12/03/2003
Marcelo Saviski
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_eek.gif[/img:75c896cd3e][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
Clique aqui para fazer login e interagir na Comunidade :)