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

[resolvido] Incompatible Types: 'char' And 'shortstring


*_Felipe_*

Pergunta

O erro é: Incompatible types: 'Char' and 'ShortString'

esta na linha destacada:

for q2:=z to z1 do

begin

Feeder[ncx].head3[aux] := Feeder[ncx].head3[aux] + Cumulative[ncx].fch3[aux][q2];

end;

a variavel "head3" é vetor tipo string, dentro de um record (Feeder).

"Head3" deve receber apenas alguns caracteres da variavel "fch3", que tambem é um vetor.

a variavel "q2" é o numero do(s) caracter(es) à ser pego da variavel "fch3", e "aux" é a posiçao no vetor!

se eu tento utilizar a funçao "strcat" assim:

StrCat(Feeder[ncx].head3[aux], Cumulative[ncx].fch3[aux][q2]);

o erro muda: [Error] Principal.pas(1280): Incompatible types: 'Char' and 'PAnsiChar'

No mesmo programa tenho esta linha:

PCB[ncx].tempom := PCB[ncx].tempom + Cumulative[ncx].cum[q5];

e ela funciona, portanto o erro está no vetor

mas não sei oque fazer. Se precisar eu boto uma parte maior do codigo.

Desde já agradeço =)

Editado por *_Felipe_*
Link para o comentário
Compartilhar em outros sites

8 respostass a esta questão

Posts Recomendados

  • 0

TCumulative = record
    xc, xch:integer;
    cum,hc1,hc2,hc3:string;
    fc,ncf,fch1,fch2,fch3:array[0..50] of string;

TFeeder = record
    feeder, ofpcb, comment, quant, erros, aproveitamento:string;
    head1, erros1, head2, erros2, head3, erros3:string;
    idpcb:integer;

acredito eu que o "shortstring" dito no erro, é porque "head3" está sendo adicionado de apenas um caracter de "fch3"!

p.s: como se bota aquela janelinha "quote" que voces usam para exibir o cogido fonte?

Editado por Micheus
Adicionado o delimitador de código [code] [/code]
Link para o comentário
Compartilhar em outros sites

  • 0

Opa

Então fera não consegui emular o problema aqui não, que da pra arrumar

isso dá agora pra te ajudar eu teria que conseguir emular...

Tem como você passar parte do código, dessa parte ai principalmente?

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
Então fera não consegui emular o problema aqui não, que da pra arrumar

isso dá agora pra te ajudar eu teria que conseguir emular...

Tem como você passar parte do código, dessa parte ai principalmente?

Churc, uma forcinha neste sentido...

procedure TForm1.Button1Click(Sender: TObject);
type
  TCumulative = record
    xc, xch:integer;
    cum,hc1,hc2,hc3:string;
    fc,ncf,fch1,fch2,fch3:array[0..50] of string;
  end;
  TFeeder = record
    feeder, ofpcb, comment, quant, erros, aproveitamento:string;
    head1, erros1, head2, erros2, head3, erros3:string;
    idpcb:integer;
  end;
var
  Cumulative :array[1..5] of TCumulative;
  Feeder :array[1..5] of TFeeder;
  q2, z, z1,
  ncx, aux :integer;
begin
  FillChar(Cumulative, SizeOf(Cumulative), 0);
  FillChar(Feeder, SizeOf(Feeder), 0);
 // valores fixos para a simulação. (lembrando que o erro é de compilação)
  ncx := 1;  // índice de controle dos arrays Feeder e Cumulative
  aux := 0;  // índice de controle do array Cumulative.fch3
  Cumulative[ncx].fch3[aux] := 'testando o erro de conversão';
 // índice de controle do início de varredura do string Cumulative.fch3[aux]
  z := 1;   // índice da posição inícial da varredura
  z1 := 15; // índice da posição final da varredura - menor que tamanho do texto

  for q2:=z to z1 do
  begin
    Feeder[ncx].head3[aux] := Feeder[ncx].head3[aux] + Cumulative[ncx].fch3[aux][q2];
  end;
end;

Link para o comentário
Compartilhar em outros sites

  • 0

Opa

Aee grande Micheus! :D

Então, a parte de incompatibilidade da pra resolver assim

uses

StrUtils;

//naquela parte:

for q2:=z to z1 do

begin

StuffString(Feeder[ncx].head3[aux], 1, Length(Feeder[ncx].head3[aux]), Cumulative[ncx].fch3[aux][q2]);

end;

Agora tem algum problema ai, porque da um Access Violation...

ainda não achei ainda onde, ta foda de pensar ashushu

Tem alguma ideia Micheus?

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

esse programa ta me dando uma dor de cabeça, acho que ate vo te que estender o estagio :S

bom .. esse programa serve pra fazer a leitura de um relatorio

gerado por uma maquina, aqui da empresa, que coloca componentes em uma placa

eu não coloquei o StuffString() prq da AccessViolation...

procedure TPrincipalForm.Button1Click(Sender: TObject);
type
  TCumulative = record
    xc, xch:integer;
    cum,hc1,hc2,hc3:string;
    fc,ncf,fch1,fch2,fch3:array[0..50] of string;
  end;
  TPCB = record
    nome,quant,porc,tempot,tempom,quantc:string;
    idmaq:integer;
  end;
  TFeeder = record
    feeder, ofpcb, comment, quant, erros, aproveitamento:string;
    head1, erros1, head2, erros2, head3, erros3:string;
    idpcb:integer;
  end;
  THead1 = record
    head,acoes,errosf,errosm:string;
    idpcb:integer;
  end;
  THead2 = record
    head,acoes,errosf,errosm:string;
    idpcb:integer;
  end;
  THead3 = record
    head,acoes,errosf,errosm:string;
    idpcb:integer;
  end;
var
  Cumulative: array[0..9] of TCumulative;
  Feeder: array[0..49] of TFeeder;
  PCB: Array[0..9] of TPCB;
  Head1: Array[0..29] of THead1;
  Head2: Array[0..29] of THead2;
  Head3: Array[0..29] of THead3;
  rel,fname,mata,tlg,tus,rat:string;
  i:integer;
  x,ml,nc:integer;
  xt, xth:integer;
  xczote,xchzote,ncx:integer;
  tri,ht1,ht2,ht3: string;
  cc,c1,c2,c3,c4,c5,c6,che,ch1: boolean;
  w,que,q1,q2,q3,q4,q5,q6,z,z1,aux:integer;
  mtempol,mtempou,mporc:string;
  cnome,cquant,cporc,ctempot,ctempom,cquantc:string;
  cffeeder,cfcomment,cfquant,cferros,cfaproveitamento: array[0..50] of string;
  chhead1,chacoes1,cherrosf1,cherrosm1:string;
  chhead2,chacoes2,cherrosf2,cherrosm2:string;
  chhead3,chacoes3,cherrosf3,cherrosm3:string;
  cfhead1,cferros1,cfhead2,cferros2,cfhead3,cferros3: array[0..50] of string;
begin
  fname:= InputBox(fname,'Caminho do arquivo:','c:\gerar brd\');
  AssignFile(Input,fname);
  reset(Input);
  readln(mata);

  //e segue usando readln e armazenando variaveis, na qual uma delas é o fch3. 
  //porém as variaveis estão assim(exemplo): fch3 = 'H3=     81    1    0'; e neste caso, significa que a cabeça 3, agiu 81 vezes e errou 1, então tenho que dividir ela em:
  //head3 = 81 e erros3 = 1
  //os booleans c1,c2 e c3 servem para alternar entre os valores.
  //o boolean che serve para quando um valor for encontrado, então procura o proximo valor.

  for ncx:=0 to nc do
  begin
  //vai separando variaveis, até chegar na vez do fch3
  ...
  ...
  ...
    for aux:=0 to Cumulative[ncx].xch do
    begin
      que:=0;
      q1:=0;
      q2:=0;
      q3:=0;
      c1:=false;
      c2:=true;
      c3:=true;
      che:=false;
      for que:=1 to 20 do
      begin
        if c1 = false then
        begin
          if che=false then
          begin
            if Cumulative[ncx].fch3[aux][que] = ' ' then
            begin
              che:=true;
            end;
          end
          else
          begin
            if Cumulative[ncx].fch3[aux][que] <> ' ' then
            begin
              c1:=true;
              c2:=false;
              che:=false;
              ch1:=false;
            end;
          end;
        end;
        if c2 = false then
        begin
          if ch1 = false then
          begin
            z:=que;
            ch1:=true;
          end;
          if che = false then
          begin
            if Cumulative[ncx].fch3[aux][que] = ' ' then
            begin
              z1:=que-1;
              che:=true;
              for q2:=z to z1 do
              begin
                Feeder[ncx].head3[aux] := Feeder[ncx].head3[aux] + Cumulative[ncx].fch3[aux][q2]);
              end;
            end;
          end
          else
          begin
            if Cumulative[ncx].fch3[aux][que] <> ' ' then
            begin
              c2:=true;
              c3:=false;
              che:=false;
              ch1:=false;
            end;
          end;
        end;
        if c3 = false then
        begin
          if ch1 = false then
          begin
            z:=que;
            ch1:=true;
          end;
          if che = false then
          begin
            if Cumulative[ncx].fch3[aux][que] = ' ' then
            begin
              z1:=que-1;
              che:=true;
              for q3:=z to z1 do
              begin
                Feeder[ncx].erros3[aux] := Feeder[ncx].erros3[aux] + Cumulative[ncx].fch3[aux][q3];
              end;
              c3:=true;
            end;
          end;
        end;
      end;
    end;
  end;
end;

Editado por Churc
Link para o comentário
Compartilhar em outros sites

  • 0

Opa

Mas então, não é o StuffString que da o AccessViolation e sim aquela leitura ali:

Feeder[ncx].erros3[aux] := Feeder[ncx].erros3[aux] + Cumulative[ncx].fch3[aux][q3];

Isto posso te garantir... a rotina StuffString(); nada mais nada menos usa a rotina Copy();

Eu falei com uns gringo eles disseram várias coisas sobre isso mas eu não entendi nada!

AIUAHE

Se te ajudar olha

if you add 2 character then you have a Shortstring type

for example

var a,b:char;

s:shortstring;

begin

a:='A';

b:='B';

s:=a+b; // s= 'AB'

end;

your error say that 'AB' is not char, and said right.

you cannot convert a shortstring to char. but you can use one of (former or later) , see following code:

for q2:=z to z1 do

begin

Feeder[ncx].head3[aux] := (Feeder[ncx].head3[aux] +

Cumulative[ncx].fch3[aux][q2])[1];

end;

the code have not syntax error but now have logical error .

im forget to say, if you want add two character as a order code then use following code:

var a,b:char;

c:char;

begin

c:=char(ord(a)+ord(B))

end;

Hehe.

A statement of what you are trying to do would have been sensible here.

Anyhow...

> FillChar(Cumulative, SizeOf(Cumulative), 0);

> FillChar(Feeder, SizeOf(Feeder), 0);

Don't do that, i.e., use FillChar on a record that has one or more fields

with a compiler-managed type like string. If you want a short(ish) way to

set the numerical values to 0, do this:

procedure TForm1.Button1Click(Sender: TObject);

type

...

const

EmptyCumulative: TCumulative = ();

EmptyFeeder: TFeeder = ();

var

...

begin

Cumulative := EmptyCumulative;

Feeder := EmptyFeeder;

...

end;

> for q2:=z to z1 do

> begin

> //ERROR is here

> Feeder[ncx].head3[aux] := Feeder[ncx].head3[aux] +

> Cumulative[ncx].fch3[aux][q2];

> end;

Well, you've declared Feeder[ncx].head3 as a single string; hence,

Feeder[ncx].head3[aux] accesses the aux'th character of the string. In

contrast, Cumulative[ncx].fch3 is an array of 51 strings. So,

Cumulative[ncx].fch3[aux] accesses the aux'th string, and

Cumulative[ncx].fch3[aux][q2] the q2'th character of that string. Add two

characters together, and what do you get in Delphi-land? A string, not a

character ('a' + 'b' = 'ab') - hence the error.

So, if your aim is to add the ordinal values of the two characters

together, adapt the code Ahmadi has given.

However, your code has a further problem: for in the first iteration of

the loop, you shouldn't be reading Feeder[ncx].head3[aux] anyhow, since

the string is empty.

Bom se te ajudar ta ai assahuhus

abraço

Link para o comentário
Compartilhar em outros sites

  • 0

eu ate entendi oqe os gringos disseram

mas era muito complicado...

mas clareou uma ideia

resolvi descomplicar e criei uma variavel para receber os caracteres, já que o problema na recepçao acontecia apenas com variaveis que tem vetor

ficou assim:

aux1:='';
          for q2:=z to z1 do
          begin
            aux1 := aux1 + Cumulative[ncx].fch3[aux][q2];
          end;
          Feeder[ncx].head3 := aux1;

n sei como n tinha pensado nisso antes ehuieuhe

abraço e valeu pela ajuda na duvida d antes =D

Editado por *_Felipe_*
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,1k
    • Posts
      651,8k
×
×
  • Criar Novo...