Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-04

Can I define a custom "simple" type for my applications?

13 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I need a "new" boolean type in my applications that support three values. True, False and Null. Null value means undefined and has various uses and gets handled differently to True or False. Is this possible in Free Pascal?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

dmitry boyarintsev
to Mattias Gaertner: On Mon, 6 Apr 2009 19:21:50 +0200 TGraemeBoolean = (gbNull, gbTrue, gbFalse); Mattias
TGraemeBoolean = (gbNull, gbTrue, gbFalse);

imho, gbFalse should come before gbTrue.

how about that?

interface
TGraemeBoolean = (gbNull = -1, gbFalse = 0, gbTrue =1);
function dbBool(g: TGrameBoolean): Boolean; inline;
function dbAssigned(gTGrameBoolean): Boolean; inline;
implementation
function dbBool(g: TGrameBoolean): Boolean; inline;
begin
  Result := g  gbFalse;
end;
function dbAssigned(gTGrameBoolean): Boolean; inline;
begin
  Result := g  gbNil;
end;

Reply by email

Graeme Geldenhuys
to dmitry boyarintsev
dmitry boyarintsev wrote 5 lines
TGraemeBoolean = (gbNull = -1, gbFalse = 0, gbTrue =1); function dbBool(g: TGrameBoolean): Boolean; inline; function dbAssigned(gTGrameBoolean): Boolean; inline;

Dope! Now why didn't I think of that. :-) Thank you very much!

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 7 lines
> > TGraemeBoolean = (gbNull = -1, gbFalse = 0, gbTrue =1); > > function dbBool(g: TGrameBoolean): Boolean; inline; > function dbAssigned(gTGrameBoolean): Boolean; inline; Dope! Now why didn't I think of that. :-) Thank you very much!

Have a look at $packenum btw if you go that way.

Reply by email

Marco van de Voort
to dmitry boyarintsev

In our previous episode, dmitry boyarintsev said:

> Have a look at $packenum btw if you go that way. what's the reason? i guess it's not to be used for streaming operation.

Well, you never know. Shared memory is another possibility btw.

btw, is there $packsets? (for sets aligment?)

No, not that I know.

Reply by email

Jonas Maebe
to Marco van de Voort: In our previous episode, dmitry boyarintsev said: Oops I apparantly looked at outdated…
Marco van de Voort wrote
Oops I apparantly looked at outdated docs (on scenergy): http://www.freepascal.org/docs-html/prog/progsu59.html#x66-640001.1.59

That documentation is not really complete. The supported settings are:
* FIXED, DEFAULT, NORMAL: the default behaviour, and behaves as described in the docs.
* 1, 2, 4: the set size depends on both the low and high value of the set element type (e.g., a set of 16..23 will be 1 byte in case of {$packset 1}), with
a) the lower bound rounded down to a multiple of the packset setting expressed in bits
b) the upper bound rounded up to 'a multiple of the packset setting (in bits)' minus 1 (e.g., 24 is a multiple of 8 bits in the above example -> -1 = 23)
c) if the set size would be 3 bytes after the above calculation, it's changed to 4 bytes
d) if the set size would be greater than 4 bytes after the above calculation, it's changed to 32 bytes.
* {$packset 8} is also supported, but kind of nonsensical in the current implementation (will always be rounded up to 32 byte, since the set size will always be > 4).

Jonas

Reply by email