preencher String Grid com Fields de tipo diferente

Delphi

15/09/2008

Bom dia pessoal!!!

Estou utilizando um String Grid e o estou preenchendo com a rotina abaixo

  with DmBanco.S040 do
    begin
      First;
      For nRecords := 1 to RecordCount do
        begin
          for nFields := 0 to FieldCount-1 do
            begin
              if Fields.Fields[nFields].Value=´´ then
                strngrd.Cells[nFields,nRecords] :=´´
              else
                strngrd.Cells[nFields,nRecords] := Fields.Fields[nFields].Value;
            end;
          strngrd.RowCount := strngrd.RowCount+1;
          Next;
        end;
    end
;

Porém eu tenho um problema, eu naum sei validar o campo Integer para poder joga-lo como string no componente, causando um erro de conversão.


[b:2db711b6f5]Could not convert variant of type (String) into type (Double) [/b:2db711b6f5]

Alguém poderia me ajudar a fazer essa validação???

Obrigado

[]´s
Wagner Marrane


Wagnermarrane

Wagnermarrane

Curtidas 0

Respostas

Wdrocha

Wdrocha

15/09/2008

Olá...bom dia....


tenta fazer o seguinte.....faz um Cast para String....


with DmBanco.S040 do 
    begin 
      First; 
      For nRecords := 1 to RecordCount do 
        begin 
          for nFields := 0 to FieldCount-1 do 
            begin 
              if Fields.Fields[nFields].Value=´´ then 
                strngrd.Cells[nFields,nRecords] :=´´ 
              else 
                strngrd.Cells[nFields,nRecords] := String  (Fields.Fields[nFields].Value);// <-------- O Cast está nesta linha 
            end; 
          strngrd.RowCount := strngrd.RowCount+1; 
          Next; 
        end; 
    end




Espero ter ajudado...


Flw


GOSTEI 0
Wagnermarrane

Wagnermarrane

15/09/2008

Infelizmente continuo com o mesmo erro.

Como faço para identificar o tipo do Field que esta sendo apontado?


GOSTEI 0
Wagnermarrane

Wagnermarrane

15/09/2008

alguém poderia me ajuda?????


GOSTEI 0
Adoniram

Adoniram

15/09/2008

Acho desnecessário vc verificar se o campo está vazio e atribuir vazio e caso contrário atribuir o valor do campo. Pq vc não faz direto assim:

  with DmBanco.S040 do 
    begin 
      First; 
      For nRecords := 1 to RecordCount do 
        begin 
          for nFields := 0 to FieldCount-1 do 
             strngrd.Cells[nFields,nRecords] := Fields.Fields[nFields].AsString;
                       end; 
          strngrd.RowCount := strngrd.RowCount+1; 
          Next; 
        end; 
    end


Caso deseje saber o tipo do campo verifique o tipo da classe:
Fields.Fields[nFields] is TIntegerField
Fields.Fields[nFields] is TStringField
Fields.Fields[nFields] is TFloatField.

Espero ter ajudado.


GOSTEI 0
Wagnermarrane

Wagnermarrane

15/09/2008

Muito obrigado pela ajuda. Abaixo código corrigido

[]´s

  with DmBanco.S030 do
    begin
      First;
      For nRecords := 1 to RecordCount do
        begin
          for nFields := 0 to FieldCount-1 do
            begin
              if Fields.Fields[nFields] is TIntegerField  then
                strngrd.Cells[nFields,nRecords] := IntToStr(Fields.Fields[nFields].Value)
              else
                strngrd.Cells[nFields,nRecords] :=Fields.Fields[nFields].Value;
            end;
          strngrd.RowCount := strngrd.RowCount+1;
          Next;
        end;
    end;



GOSTEI 0
POSTAR