Forum > Beginners

About FP types

(1/2) > >>

Sergios:
Hi!
I have two questions:
1. What means directive "type" in type delaration section?

--- Quote from: systemh.inc ---Type
...
  UTF8String = type ansistring;

--- End quote ---
2. Where can I find identifiers for Byte and Boolean?

--- Quote from: ref.pdf, page 14 ---Remark: Predefined types such as Byte, Boolean and constants such as maxint are not reserved words.
They are identifiers, declared in the system unit.
--- End quote ---

taazz:

--- Quote from: Sergios on September 28, 2014, 09:08:55 am ---Hi!
I have two questions:
1. What means directive "type" in type delaration section?

--- Quote from: systemh.inc ---Type
...
  UTF8String = type ansistring;

--- End quote ---

--- End quote ---

That means that utf8string is not assign compatible with ansistring any more so unless the rtl defines some kind of auto conversion routine for it then doing some thing like this

--- Code: ---var
  vStr1 : AnsiString;
  vStr2 : Utf8string;
begin
  vstr1 := 'This is ansi';
  vstr2 := vstr1; //<--- incompatible type can't assign ansistring to utf8string
end;

--- End code ---
will raise an exception.


--- Quote from: Sergios on September 28, 2014, 09:08:55 am ---2. Where can I find identifiers for Byte and Boolean?

--- Quote from: ref.pdf, page 14 ---Remark: Predefined types such as Byte, Boolean and constants such as maxint are not reserved words.
They are identifiers, declared in the system unit.
--- End quote ---

--- End quote ---

No idea never gone looking for them.

howardpc:

--- Quote from: ref.pdf, page 14 ---Remark: Predefined types such as Byte, Boolean and constants such as maxint are not reserved words.
They are identifiers, declared in the system unit.
--- End quote ---

Actually I think part of that remark may be incorrect.
Maxint is an alias for maxSmallint which is declared in systemh.inc.
I cannot find declarations for the two types byte and boolean in the system unit (however, I may have searched wrongly).
I think they are effectively part of the Pascal language (whether or not they are technically reserved words), and are defined/declared somewhere inside the compiler, rather than in the RTL. We would need a compiler guy to guide us on this.
Boolean behaves as if it were an enumerated type declared like this:

--- Code: ---type
  boolean = (False, True);

--- End code ---

Leledumbo:

--- Quote ---Maxint is an alias for maxSmallint which is declared in systemh.inc.
--- End quote ---
SysUtils override it to MaxLongInt AFAIK.

--- Quote ---I think they are effectively part of the Pascal language (whether or not they are technically reserved words), and are defined/declared somewhere inside the compiler, rather than in the RTL
--- End quote ---
Correct, all base types are defined by the compiler. You can see a little comment in the type section of systemh.inc (shared by all supported targets). However, they are identifiers. You can perfectly override them.

--- Quote ---Boolean behaves as if it were an enumerated type declared like this:
--- End quote ---
That's exactly how the standard defines Boolean. However, enum can't mark them as reserved words so they must be internally defined.

Sergios:
I thank All for responses.
I have the other question now.
Are the following typecastings safe?:

* PWideChar(varWideString)
* WideString(varPWideChar)
* PChar(varAnsiString)
* AnsiString(varPChar)Where var[Type] is a variable of type [Type] declared in var section of code.
Thanks in advance.

Navigation

[0] Message Index

[#] Next page

Go to full version