Converter um tipo derivado em string
20/03/2017
0
Olá, sou novo em programação e tenho uma dúvida, estou resolvendo um exercício que é criar um programa que efetue o gerenciamento de dados de dez registros de uma agenda que contenha nome, endereço e telefone, criar um menu para cadastrar os dez registros, pesquisar um registro, classificar por ordem de nome os dez registros, apresentar todos os registros e sair do programa, enfim minha dúvida é no momento de classificar por ordem de nome, fiz o algoritmo da troca para ordenar os dados porém o delphi me retornou o erro [dcc32 Error] Exercicio_01.dpr(111): E2010 Incompatible types: 'string' and 'Cad_registros' segue o código o erro está justamente na linha em que x := Agenda[i] não sei como converte tipo derivado em string e se esse é o caminho correto, alguém pode me ajudar rsrs ...
//Trecho com problema if (opcao = 3) then begin for I := 1 to 2 do begin for J := I + 1 to 3 do begin if (Agenda[i].Nome > Agenda[j].Nome) then begin x := Agenda[i]; Agenda[i] := Agenda[j]; Agenda[j] := x; end; end; end; end;
//Trecho completo program Exercicio_01; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; {$REGION ' Registro '} type Cad_registros = record Nome : string; Endereco : string; Telefone : string; end; {$ENDREGION} {$REGION ' Variaveis '} var Agenda : array[1..3] of Cad_registros; var I, J, Opcao : Integer; var Pesq, X : string; var Acha : Boolean; {$ENDREGION} begin Opcao := 0; while (Opcao <> 5) do begin Writeln('**************************'); Writeln(' Menu de opcoes da agenda '); Writeln('**************************'); Writeln(Output,'1 - Cadastrar'); Writeln(Output,'2 - Pesquisar'); Writeln(Output,'3 - Classificar'); Writeln(Output,'4 - Apresentar'); Writeln(Output,'5 - Fim'); Writeln(''); Readln(Input,Opcao); if (Opcao = 1) then begin Writeln(''); Writeln('Voce escolheu a '+IntToStr(Opcao)+'a. opcao, Cadastrar dados! '); for I := 1 to 3 do begin Writeln(''); Writeln(IntToStr(i)+'o. registro da agenda.'); Write(Output,'Nome......: '); Readln(Input,Agenda[i].Nome); Write(Output,'endereco..: '); Readln(Input,Agenda[i].Endereco); Write(Output,'Telefone..: '); Readln(Input,Agenda[i].Telefone); Writeln(''); end; Writeln(' --- Fim do cadastro --- '); Writeln(''); Writeln('Escolha a proxima opcao ou - 5 para terminar!'); Writeln(''); end; if (opcao = 2) then begin Writeln(''); Writeln('Voce escolheu a '+IntToStr(Opcao)+'a. opcao, Pesquisar dados! '); Writeln(''); Writeln('Digite o nome a ser pesquisado: '); Readln(Pesq); Writeln(''); I := 1; Acha := False; while (i <= 3) and (Acha = False) do begin if (Pesq = Agenda[i].Nome) then begin Acha := True; end else begin Inc(i); end; end; if (Acha = True) then begin Writeln('Nome......: ',Agenda[i].Nome); Writeln('Endereco..: ',Agenda[i].Endereco); Writeln('Telefone..: ',Agenda[i].Telefone); Writeln(''); end else begin Writeln('Registro inconsistente!'); Writeln(''); end; end; if (opcao = 3) then begin for I := 1 to 2 do begin for J := I + 1 to 3 do begin if (Agenda[i].Nome > Agenda[j].Nome) then begin x := Agenda[i]; Agenda[i] := Agenda[j]; Agenda[j] := x; end; end; end; end; if (Opcao = 4) then begin for I := 1 to 3 do begin Writeln('Nome......: ',Agenda[i].Nome); Writeln('Endereco..: ',Agenda[i].Endereco); Writeln('Telefone..: ',Agenda[i].Telefone); Writeln(''); end; end; end; end.
Eduardo
Curtir tópico
+ 0
Responder
Posts
20/03/2017
Eduardo
Encontrei a solução o erro era que eu não estava passando a variavel X como array do mesmo tipo da variavel Agenda que é derivado postei aqui caso alguém tenha o mesmo problema.
if (opcao = 3) then begin for I := 1 to 2 do begin for J := I + 1 to 3 do begin if (Agenda[i].Nome) > (Agenda[j].Nome) then begin x[i] := Agenda[i]; Agenda[i] := Agenda[j]; Agenda[j] := x[i]; end; end; end; end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)