Fórum preencher String Grid com Fields de tipo diferente #363928
15/09/2008
0
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
Curtir tópico
+ 0Posts
15/09/2008
Wdrocha
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
15/09/2008
Wagnermarrane
Como faço para identificar o tipo do Field que esta sendo apontado?
Gostei + 0
15/09/2008
Wagnermarrane
Gostei + 0
15/09/2008
Adoniram
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
16/09/2008
Wagnermarrane
[]´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
Clique aqui para fazer login e interagir na Comunidade :)