Recent

Author Topic: How to initialize the array  (Read 24700 times)

krzynio

  • Full Member
  • ***
  • Posts: 110
    • Krzynio's home page
Re: How to initialize the array
« Reply #30 on: March 03, 2022, 09:33:03 am »
Unfortunately the same error: unit1.pas(12,37) Error: Incompatible types: got "Constant String" expected "WideChar"

and the below code is not working also:
Code: Pascal  [Select][+][-]
  1. var
  2. PLChars: array[0..17] of WideChar;
  3. i: integer;
  4. begin
  5.   PLchars[0] := 'ą';  // doesn't work
  6.   i := ord('ą'); // doesn't work,  unit1.pas(47,8) Error: Ordinal expression expected
  7.  
« Last Edit: March 03, 2022, 10:00:45 am by krzynio »
Debian 12.8 x64, / Windows 11 PL - latest updates
Lazarus 3.6

PascalDragon

  • Hero Member
  • *****
  • Posts: 6238
  • Compiler Developer
Re: How to initialize the array
« Reply #31 on: March 03, 2022, 01:57:04 pm »
Make sure that your file has a UTF-8 BOM (in Lazarus right click the text editor, then File Settings -> Encoding -> UTF-8 with BOM and then select the Change File option in the dialog), then the compiler will handle this correctly. Alternatively you can add {$codepage utf8} at the top. Without either of this the compiler will see a such a character as a 2 Byte sequence which is longer than a single character which still is AnsiChar no matter what it's assigned to.

PeterX

  • Sr. Member
  • ****
  • Posts: 439
Re: How to initialize the array
« Reply #32 on: September 01, 2024, 01:13:07 pm »
Hello, I am a beginner and I was trying to get a value from the string and put it into the array. An error message "Warning: Variable "code" of a managed type does not seem to be initialized". How do I solve it?
It's just a warning, in case you forgot to initialize the array (or other managed type, like String), and it can usually be either ignored or shut down by initializing it, for example with:
Code: Pascal  [Select][+][-]
  1. code := Default(TStringArray);
Sorry for bringing up this old Thread, but ..

Simple solution (to avoid the compiler warning ..) would have been

Code: Pascal  [Select][+][-]
  1. code := NIL;   // empty array
  2.  
or
Code: Pascal  [Select][+][-]
  1. var
  2.   code:TStringArray = NIL;
  3.  

Indeed Default does the same, but beginners probably won't find instructions for Default easily.
https://wiki.freepascal.org/Default

I myself also didn't know this by now. Still learning every day ..  :)
« Last Edit: September 01, 2024, 01:15:30 pm by PeterX »
usually using latest Lazarus release version with Windows 10 or 11

Thaddy

  • Hero Member
  • *****
  • Posts: 18529
  • Here stood a man who saw the Elbe and jumped it.
Re: How to initialize the array
« Reply #33 on: September 01, 2024, 01:57:33 pm »
Well, the wiki might be not clear, but the official documentation usually is :
https://www.freepascal.org/docs-html/rtl/system/default.html
Users should refer to the official documentation first, only then refer to the wiki.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018