Recent

Author Topic: [solved] function chr() to obtain a extended char from his integer value.  (Read 5294 times)

dcelso

  • Full Member
  • ***
  • Posts: 158
Hello to all,
In lazarus, I detected that if you put chr with a value greater than 127, the function does not return the representation of his corresponding char, instead of in delphi (any version) it return correctly the character representacion.
My example is the next:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
begin
  for i:=128 to 255 do
      Memo1.Lines.Add(inttostr(i)+': '+chr(i));
end;

The form is a simple form1 with a memo1 and a button1.

In lazarus the result text is the next:
Code: [Select]
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192: ?
193: ?
194: ?
195: ?
196: ?
197: ?
198: ?
199: ?
200: ?
201: ?
202: ?
203: ?
204: ?
205: ?
206: ?
207: ?
208: ?
209: ?
210: ?
211: ?
212: ?
213: ?
214: ?
215: ?
216: ?
217: ?
218: ?
219: ?
220: ?
221: ?
222: ?
223: ?
224: ?
225: ?
226: ?
227: ?
228: ?
229: ?
230: ?
231: ?
232: ?
233: ?
234: ?
235: ?
236: ?
237: ?
238: ?
239: ?
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:

In delphi (in this case delphi 7)
Code: [Select]
128: €
129: 
130: ‚
131: ƒ
132: „
133: …
134: †
135: ‡
136: ˆ
137: ‰
138: Š
139: ‹
140: Œ
141: 
142: Ž
143: 
144: 
145: ‘
146: ’
147: “
148: ”
149: •
150: –
151: —
152: ˜
153: ™
154: š
155: ›
156: œ
157: 
158: ž
159: Ÿ
160: 
161: ¡
162: ¢
163: £
164: ¤
165: ¥
166: ¦
167: §
168: ¨
169: ©
170: ª
171: «
172: ¬
173: ­
174: ®
175: ¯
176: °
177: ±
178: ²
179: ³
180: ´
181: µ
182: ¶
183: ·
184: ¸
185: ¹
186: º
187: »
188: ¼
189: ½
190: ¾
191: ¿
192: À
193: Á
194: Â
195: Ã
196: Ä
197: Å
198: Æ
199: Ç
200: È
201: É
202: Ê
203: Ë
204: Ì
205: Í
206: Î
207: Ï
208: Ð
209: Ñ
210: Ò
211: Ó
212: Ô
213: Õ
214: Ö
215: ×
216: Ø
217: Ù
218: Ú
219: Û
220: Ü
221: Ý
222: Þ
223: ß
224: à
225: á
226: â
227: ã
228: ä
229: å
230: æ
231: ç
232: è
233: é
234: ê
235: ë
236: ì
237: í
238: î
239: ï
240: ð
241: ñ
242: ò
243: ó
244: ô
245: õ
246: ö
247: ÷
248: ø
249: ù
250: ú
251: û
252: ü
253: ý
254: þ
255: ÿ

If it not possible to fix this problem,

Anyone know another function to get the character represation of a number?

Thanks
« Last Edit: January 29, 2013, 12:02:12 pm by dcelso »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: function chr() to obtain a extended char from his integer value.
« Reply #1 on: January 29, 2013, 11:54:20 am »
Try the following (Lazarus uses utf8 encoding by default):
Code: [Select]
uses LazUTF8;

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
  s: string;
begin
  for i:=128 to 255 do
   begin
    s:= SysToUTF8(chr(i));
    Memo1.Lines.Add(inttostr(i)+': '+s);
   end;
end;

dcelso

  • Full Member
  • ***
  • Posts: 158
Re: function chr() to obtain a extended char from his integer value.
« Reply #2 on: January 29, 2013, 12:00:11 pm »
 :), thanks.

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1931
Re: function chr() to obtain a extended char from his integer value.
« Reply #3 on: January 29, 2013, 12:16:36 pm »
This solution won't work on UTF8 Systems (Linux, Mac?)

The following would display the unicode range "Latin-1 Supplement",  but I'm not sure if this is what you are looking for.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
  s: AnsiString;
begin
  for i:=160 to 255 do
   begin
    s:= UTF8Encode(WideChar(Word(i)));
    Memo1.Lines.Add(inttostr(i)+': '+s);
   end;
end;
       

 

TinyPortal © 2005-2018