Ord et Char

cs_apz Messages postés 281 Date d'inscription dimanche 7 avril 2002 Statut Membre Dernière intervention 11 avril 2013 - 3 sept. 2002 à 14:03
cs_Nono40 Messages postés 962 Date d'inscription mercredi 3 avril 2002 Statut Membre Dernière intervention 12 septembre 2006 - 4 sept. 2002 à 00:30
Salut a tous,

en executant ce code la fonction Ord ne marche pâs sur le contenu du stringgrid :

----------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
i, j, k : integer;
s : Char;
begin
for j:=1 to stringgrid1.rowcount-1 do
begin
for k:=0 to StringGrid1.ColCount-1 do
begin
if not ((k+j) mod 2 = 0) then
StringGrid1.Cells[k,j]:=Char(k+j)
else
begin
s:= IntToStr(char(StringGrid1.cells[k-1,j])) ;
StringGrid1.Cells[k,j]:=IntToStr(Ord(s));
end;
end;
end;
end;
----------------

un petit test pour resoudre ce prob !

Meric [:-)]

2 réponses

PhGORMAND Messages postés 54 Date d'inscription jeudi 3 janvier 2002 Statut Membre Dernière intervention 20 juillet 2006
3 sept. 2002 à 16:58
Salut .
Le type Char, a une largeur de un octet.
tu tentes un transtypage incorrecte
s:= IntToStr(char(StringGrid1.cells[k-1,j])) ;

La propriété Cells de la stringµGrid, est une liste
de chaines du type String donc une classe. S ne
peut pas contenir la représentation Char de
plusieurs éléments (String).
Mais tu peux récupérer pour 1 élément de la chaine.
Exemple :
s:= IntToStr(char(StringGrid1.cells[k-1,j][1])) ;

ou pour écrir plus lisiblement :
s:= StringGrid1.cells[k-1,j][1] ;//Récupère le 1°
//caratère de la chaine

s:= IntToStr(char(s));
StringGrid1.Cells[k,j]:=IntToStr(Ord(s[1]));

A +.
0
Rejoignez-nous