Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Erro ao declarar Variável


nsouza

Pergunta

2 respostass a esta questão

Posts Recomendados

  • 0
estou fazendo um sistema no delphi 2007 e precisei declarar uma variavel do tipo StringList;

FStringList : StringList;

Só que esta me retornando o erro:

Undeclareted indentifies 'StringList '

O que devo declarar para corrigir este problema?

Um exemplo bem simples

uses classes;

procedure TForm1.Button1Click(Sender: TObject);
var
  animal : TStringList;            // Define a variavel lista de strings
  i      : Integer;
begin
  // Define um objeto string list, e aponta para a variavel
  animal := TStringList.Create;

  // Adicionar os nomes de animais a lista
  animal.Add('Gato');
  animal.Add('Rato');
  animal.Add('Coelho');

  //  Mostrar a lista
  for i := 0 to animal.Count-1 do
    ShowMessage(animal[i]);  // animal[i] é igual a animal.Strings[i]

  // Limpar a lista de objetos
  animal.Free;
end;
Outros exemplos:
Example code : Using name-value strings 
var
  names  : TStringList;            // Define our string list variable
  ageStr : String;
  i      : Integer;
begin
  // Define a string list object, and point our variable at it
  names := TStringList.Create;

  // Now add some names to our list
  names.CommaText := 'Neil=45, Brian=63, Jim=22';

  // And now find Brian's age
  ageStr := names.Values['Brian'];

  // Display this value
  ShowMessage('Brians age = '+ageStr);

  // Now display all name and age pair values
  for i := 0 to names.Count-1 do
  begin
    ShowMessage(names.Names[i]+' is '+names.ValueFromIndex[i]);
  end;

  // Free up the list object
  names.Free;
end;

Show full unit code 
   Brians age is 63
   Neil is 45
   Brian is 63
   Jim is 22
   

Example code : Using DelimitedText, Delimiter and QuoteChar 
var
  cars : TStringList;            // Define our string list variable
  i    : Integer;
begin
  // Define a string list object, and point our variable at it
  cars := TStringList.Create;

  // Now add some cars to our list - using the DelimitedText property
  // with overriden control variables
  cars.Delimiter := ' ';        // Each list item will be blank separated
  cars.QuoteChar := '|';        // And each item will be quoted with |'s
  cars.DelimitedText := '|Honda Jazz| |Ford Mondeo| |Jaguar "E-type"|';

  // Now display these cars
  for i := 0 to cars.Count-1 do
    ShowMessage(cars[i]);       // cars[i] equates to cars.Strings[i]

  // Free up the list object
  cars.Free;
end;

Show full unit code 
   Honda Jazz
   Ford Mondeo
   Jaguar "E-type"

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
estou fazendo um sistema no delphi 2007 e precisei declarar uma variavel do tipo StringList;

FStringList : StringList;

Só que esta me retornando o erro:

Undeclareted indentifies 'StringList '

O que devo declarar para corrigir este problema?

Um exemplo bem simples

uses classes;

procedure TForm1.Button1Click(Sender: TObject);
var
  animal : TStringList;            // Define a variavel lista de strings
  i      : Integer;
begin
  // Define um objeto string list, e aponta para a variavel
  animal := TStringList.Create;

  // Adicionar os nomes de animais a lista
  animal.Add('Gato');
  animal.Add('Rato');
  animal.Add('Coelho');

  //  Mostrar a lista
  for i := 0 to animal.Count-1 do
    ShowMessage(animal[i]);  // animal[i] é igual a animal.Strings[i]

  // Limpar a lista de objetos
  animal.Free;
end;
Outros exemplos:
Example code : Using name-value strings 
var
  names  : TStringList;            // Define our string list variable
  ageStr : String;
  i      : Integer;
begin
  // Define a string list object, and point our variable at it
  names := TStringList.Create;

  // Now add some names to our list
  names.CommaText := 'Neil=45, Brian=63, Jim=22';

  // And now find Brian's age
  ageStr := names.Values['Brian'];

  // Display this value
  ShowMessage('Brians age = '+ageStr);

  // Now display all name and age pair values
  for i := 0 to names.Count-1 do
  begin
    ShowMessage(names.Names[i]+' is '+names.ValueFromIndex[i]);
  end;

  // Free up the list object
  names.Free;
end;

Show full unit code 
   Brians age is 63
   Neil is 45
   Brian is 63
   Jim is 22
   

Example code : Using DelimitedText, Delimiter and QuoteChar 
var
  cars : TStringList;            // Define our string list variable
  i    : Integer;
begin
  // Define a string list object, and point our variable at it
  cars := TStringList.Create;

  // Now add some cars to our list - using the DelimitedText property
  // with overriden control variables
  cars.Delimiter := ' ';        // Each list item will be blank separated
  cars.QuoteChar := '|';        // And each item will be quoted with |'s
  cars.DelimitedText := '|Honda Jazz| |Ford Mondeo| |Jaguar "E-type"|';

  // Now display these cars
  for i := 0 to cars.Count-1 do
    ShowMessage(cars[i]);       // cars[i] equates to cars.Strings[i]

  // Free up the list object
  cars.Free;
end;

Show full unit code 
   Honda Jazz
   Ford Mondeo
   Jaguar "E-type"

abraço

(Resolvido) Obrigado

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...