Difference between revisions of "Talk:Character and string types"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
  
 
I've tested (Lazarus 1.2.2 r44758 FPC 2.6.4 i386-win32-win32/win64 and Lazarus 1.3 r45097M FPC 2.7.1 i386-win32-win32/win64 on Win7)
 
I've tested (Lazarus 1.2.2 r44758 FPC 2.6.4 i386-win32-win32/win64 and Lazarus 1.3 r45097M FPC 2.7.1 i386-win32-win32/win64 on Win7)
<source>
+
<syntaxhighlight lang="pascal">
 
procedure TForm1.Button1Click(Sender: TObject);
 
procedure TForm1.Button1Click(Sender: TObject);
 
type
 
type
Line 16: Line 16:
 
   Caption:=IntToStr(ord(aOldString4[4]));
 
   Caption:=IntToStr(ord(aOldString4[4]));
 
end;
 
end;
</source>
+
</syntaxhighlight>
  
 
I got different results, but not #0 for ''aOldString4[4]''. So, do I have to update the facts or do I missunderstood the statement?
 
I got different results, but not #0 for ''aOldString4[4]''. So, do I have to update the facts or do I missunderstood the statement?
Line 56: Line 56:
 
:Hope I fixed that. --[[User:Bart|Bart]] ([[User talk:Bart|talk]]) 18:07, 15 January 2017 (CET)
 
:Hope I fixed that. --[[User:Bart|Bart]] ([[User talk:Bart|talk]]) 18:07, 15 January 2017 (CET)
 
::I believe you did a magnificent job already there Bart. Thank you very much for that, and apologies for being lazy myself. I noticed there are also many inconsistencies with regards to using anchors (or not) so my initial thought was to mark this as "links broken" and fix it after it was more clear to me for which case(s) to use anchors (or not). At the least you've made the links point to relevant reading material now. :-) --[[User:Molly|Molly]] ([[User talk:Molly|talk]]) 20:22, 15 January 2017 (CET)
 
::I believe you did a magnificent job already there Bart. Thank you very much for that, and apologies for being lazy myself. I noticed there are also many inconsistencies with regards to using anchors (or not) so my initial thought was to mark this as "links broken" and fix it after it was more clear to me for which case(s) to use anchors (or not). At the least you've made the links point to relevant reading material now. :-) --[[User:Molly|Molly]] ([[User talk:Molly|talk]]) 20:22, 15 January 2017 (CET)
 +
I had to redo them; they all pointed to an off-by-one page (links to refsu10.html should be to refsu9.html and so on). Looks like the doc URIs change(?) --[[User:Lucamar|Lucamar]] ([[User talk:Lucamar|talk]]) 04:23, 22 September 2018 (CEST)

Latest revision as of 00:21, 11 February 2020

Is the sentence in Character_and_string_types#Array_of_Char, delivers: a b c d #0 since arrays are filled with null-bytes in Free Pascal correct?!

I've tested (Lazarus 1.2.2 r44758 FPC 2.6.4 i386-win32-win32/win64 and Lazarus 1.3 r45097M FPC 2.7.1 i386-win32-win32/win64 on Win7)

procedure TForm1.Button1Click(Sender: TObject);
type
  TOldString4 = array[0..4] of char;
var
  aOldString4: TOldString4;
begin
  aOldString4[0] := 'a';
  aOldString4[1] := 'b';
  aOldString4[2] := 'c';
  aOldString4[3] := 'd';
  writeln('['+aOldString4[4]+']');
  Caption:=IntToStr(ord(aOldString4[4]));
end;

I got different results, but not #0 for aOldString4[4]. So, do I have to update the facts or do I missunderstood the statement?

Thanks --Michl 23:10, 1 June 2014 (CEST)

That statement is indeed completely bogus, there is no guarantee whatsoever regarding the content of that array element. Maybe the author was confused because of dynamic arrays, whose empty positions are initially initialised with 0 (or #0, or nil, or ...).
Jonas 11:37, 2 June 2014 (CEST)
Thank you for your comment! I think, its maybe a bug, cause if the type "OldString" is declared in the procedure, the statement is false, otherwise seems to vote. I asked in the forum.
--Michl 13:46, 2 June 2014 (CEST)
All global variables are always initialised with 0/#0/nil/... That is documented in the manual, has nothing to do with array of char, and should therefore not be mentioned here because it is orthogonal.
Jonas 14:43, 2 June 2014 (CEST)
Thank you Jonas, I did not question your statement was just surprised that when several attempts always an array filled with # 0 was created. Strange coincidences, please excuse my rude behavior and my not so good English.
I have now differentiated by static and dynamic array of char. If you or anyone else wants to, so someone could let's see, whether in terms of content and of the spelling, is in order.
Thank you! --Michl 21:19, 2 June 2014 (CEST)

Old

Doesn't ANSIChar contain an ANSI character instead of ASCII? I.e. it is codepage dependent but can contain byte values 0..255?

--BigChimp 15:28, 28 December 2013 (CET)

This is the information of the official FPC documentation. I will do additional research.
--Jwdietrich 15:33, 28 December 2013 (CET)
Yes, I suspect the official FPC documentation is wrong/incomplete ;)
BTW: thanks for writing this page - it's very helpful!
--BigChimp 16:53, 28 December 2013 (CET)
Thanks for your positive feedback. In fact, it is ANSI. Although the official Free Pascal documentation states that a char contains an ASCII character, is is stored as a byte to use extended ASCII or ANSI.
--Jwdietrich 16:55, 28 December 2013 (CET)

Wrong links

The links that can be found in each individual subsection points to the wrong location of the (online FPC) documentation. Maintaining wiki's is fun ! ;-) --Molly (talk) 13:35, 15 January 2017 (CET)

Hope I fixed that. --Bart (talk) 18:07, 15 January 2017 (CET)
I believe you did a magnificent job already there Bart. Thank you very much for that, and apologies for being lazy myself. I noticed there are also many inconsistencies with regards to using anchors (or not) so my initial thought was to mark this as "links broken" and fix it after it was more clear to me for which case(s) to use anchors (or not). At the least you've made the links point to relevant reading material now. :-) --Molly (talk) 20:22, 15 January 2017 (CET)

I had to redo them; they all pointed to an off-by-one page (links to refsu10.html should be to refsu9.html and so on). Looks like the doc URIs change(?) --Lucamar (talk) 04:23, 22 September 2018 (CEST)