[fpc-pascal] distinct types and type identifier

ik idokan at gmail.com
Wed Jan 30 10:47:58 CET 2008


type
  TfpgColor = type longword;

means that you have a new type in the same *range* of longword. That
means that you can assign the same number range, but if you have a
variable that is a longword, and you wish to assigned the value to a
TfpgColor, then you must cast it, or the compiler will tell you that
it expect a TfpgColor content (unless there is a bug ;)).

Ido

On Jan 30, 2008 11:30 AM, Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
> Hi,
>
> Below is from the Kylix 3 help.
>
> --------------------------[ copy ]------------------------------
> Type identity is almost straightforward. When one type identifier is
> declared using another type identifier, without qualification, they
> denote the same type. Thus, given the declarations
> type
>   T1 = Integer;
>   T2 = T1;
>   T3 = Integer;
>   T4 = T2;
>
> T1, T2, T3, T4, and Integer all denote the same type. To create
> distinct types, repeat the word type in the declaration. For example,
> type TMyInteger = type Integer;creates a new type called TMyInteger
> which is not identical to Integer.
> --------------------------[ end ]------------------------------
>
> So when am I supposed to use
>
> type
>   TfpgColor = longword;
>
> vs
>
> type
>   TfpgColor = type longword;
>
> ???
> What's the actual difference between them?  I have used the first
> option (declaration) in the fpGUI project. For things like:
>
> const
>   clBlue = TfpgColor($0000FF);
>
>
> Is the above the same as what the Free Pascal documentation describes
> below?  Or is this something different?
>
> --------------------------[ copy ]------------------------------
> The last class, type identifier, is just a means to give another name
> to a type. This presents a way to make types platform independent, by
> only using these types, and then defining these types for each
> platform individually. The programmer that uses these units doesn't
> have to worry about type size and so on.
> --------------------------[ end ]------------------------------
>
>
> Regards,
>   - Graeme -
>
>
> _______________________________________________
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
http://ik.homelinux.org/



More information about the fpc-pascal mailing list