Ir ao conteúdo
  • Cadastre-se

Pascal/Delphi Dificuldade em Listar pessoas cadastradas


Ir à solução Resolvido por SamuraiOcidental,

Posts recomendados

Estou tendo dificuldade em salvar os dados do usuário, sendo ele cliente ou vendedor, alguém poderia me ajudar?
As variáveis com 's' são as que eu pretendo guardar os dados para realizar a listagem.

 

Segue código em anexo:

 

Classe principal do FORM.

unit CadastroVendedorCliente;

interface

uses
  Unit1,
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabCliente: TTabSheet;
    TabVendedor: TTabSheet;
    Panel1: TPanel;
    ButtonSave: TButton;
    EditNome: TEdit;
    EditIdade: TEdit;
    Label1: TLabel;
    Label6: TLabel;
    EditVencimento: TEdit;
    EditEndereco: TEdit;
    Label2: TLabel;
    ListBox1: TListBox;
    ButtonList: TButton;
    EditTipoVendedor: TEdit;
    EditComissao: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label3: TLabel;
    procedure ButtonSaveClick(Sender: TObject);
    procedure ButtonListClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    lista: array of array of string;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ButtonListClick(Sender: TObject);
var
  Cliente: TCliente;
begin
  Cliente := TCliente.Create;
  lista[0, 0] := Cliente.matriz[0, 0];

  ListBox1.Items.Add(lista[0, 0]);
end;

procedure TForm1.ButtonSaveClick(Sender: TObject);
var
  Pessoa: TPessoa;
  Cliente: TCliente;
  Vendedor: TVendedor;

  // Cliente
  dia: integer;
  endereco: string;

  // Vendedor
  comissao: currency;
  tipo: string;

begin
  SetLength(lista, 0, 2);
  Pessoa := TPessoa.Create;
  if TabCliente.Visible = true then
  begin
    Cliente := TCliente.Create;
    Cliente.nome := EditNome.Text;
    Cliente.idade := StrToint(EditIdade.Text);
    Cliente.dia := StrToint(EditVencimento.Text);
    Cliente.endereco := EditEndereco.Text;
    Cliente.Cadastro;
  end
  else
  begin
    Vendedor := TVendedor.Create;
    Vendedor.nome := EditNome.Text;
    Vendedor.idade := StrToint(EditIdade.Text);
    Vendedor.comissao := StrToCurr(EditComissao.Text);
    Vendedor.tipo := EditTipoVendedor.Text;
    Vendedor.Cadastro;
  end;

end;

end.

 

Onde estão as classes TCliente, TVendedor:

 

unit Unit1;

interface

type
  TPessoa = class(TObject)

  protected
    function Salvar: Boolean; virtual;
    function Verificar: Boolean; virtual;

  public

    matriz: array of array of string;
    nome: string;
    idade: integer;
    function Cadastro: Boolean;

  end;

Type
  TCliente = class(TPessoa)

  protected
    function Salvar: Boolean; override;
    function Verificar: Boolean; override;

  public
    dia: integer;
    endereco: string;
    function Cadastro: Boolean;

  end;

Type
  TVendedor = class(TPessoa)

  protected
    function Salvar: Boolean; override;
    function Verificar: Boolean; override;

  public
    comissao: Currency;
    tipo: string;

    function Cadastro: Boolean;

  end;

  // ------------------------------------------------------------------------

implementation

{ TPessoa }

function TPessoa.Cadastro: Boolean;
begin
  if Verificar then
  begin
    if Salvar then
    begin
      result := true;
    end
    else
    begin
      result := false;
    end;
  end
  else
  begin
    result := false;
  end;
end;

function TPessoa.Salvar: Boolean;
var
  sIdade: integer;
  sNome: string;
begin
  sNome := nome;
  //matriz[0,0] := sNome;
  sIdade := idade;
  result := true;
end;

function TPessoa.Verificar: Boolean;
begin
  if (nome <> ' ') and (idade > 0) and (idade <= 130) then
  begin
    result := true;
  end
  else
  begin
    result := false;
  end;
end;

{ TCliente }

function TCliente.Cadastro: Boolean;
begin
  Verificar;
end;

function TCliente.Salvar: Boolean;
VAR
  sDia: integer;
  sEndereco: string;
begin
  if inherited then
  begin
    sDia := dia;
    sEndereco := endereco;
    result := true;
  end
  else
  begin
    result := false;
  end;

end;

function TCliente.Verificar: Boolean;
begin
  if inherited then
  begin
    if (dia > 0) and (dia <= 31) and (endereco <> '') then
    begin
      if Salvar then
      begin
        result := true;
      end
      else
      begin
        result := false;
      end;
    end
    else
    begin
      result := false;
    end;
  end
  else
  begin
    result := false;
  end;
end;

{ TVendedor }

function TVendedor.Cadastro: Boolean;
begin
  Verificar;
end;

function TVendedor.Salvar: Boolean;
VAR
  sComissao: Currency;
  sTipo: string;
begin
  if inherited then
  begin
    sComissao := comissao;
    sTipo := tipo;
    result := true;
  end
  else
  begin
    result := false;
  end;
end;

function TVendedor.Verificar: Boolean;
begin
  if inherited then
  begin
    if (comissao > 0) and (tipo <> '') then
    begin
      if Salvar then
      begin
        result := true;
      end
      else
      begin
        result := false;
      end;
    end
    else
    begin
      result := false;
    end;
  end
  else
  begin
    result := false;
  end;
end;

end.

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...