Sign in Join

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

Mailing lists / fpc-devel / 2007-10

types in xlib unit

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

In the xlib.pp unit the following types are defined. How are you supposed to work with a record structure that contains nothing? Does it the act like a Pointer type?

--------------- [xlib.pp] ------------------

   PXIM = ^TXIM;
   TXIM = record
     end;
   PXIC = ^TXIC;
   TXIC = record
     end;

----------------- END ------------------

I've got them redefined a bit, including a few X<whatever> methods so I could use them more easily.

-------------- [as in fpGUI] -------------

  TXIC = record
    dummy: Pointer;
  end;
  PXIC = ^TXIC;
  TXIM = record
    dummy: Pointer;
  end;
  PXIM = ^TXIM;

------------------- END ------------------

// redefines of Xlib functions
function XmbLookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar;
    len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external;
function Xutf8LookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar;
    len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external;

Regards,
- Graeme -

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

Reply by email

ik
to Graeme Geldenhuys

On C some records are "magically" created, and you do not know their content. So you can use either a pointer, or an empty record, and use a pointer to that empty pointer.

Ido

Graeme Geldenhuys wrote 57 lines
Hi, In the xlib.pp unit the following types are defined. How are you supposed to work with a record structure that contains nothing? Does it the act like a Pointer type? --------------- [xlib.pp] ------------------ PXIM = ^TXIM; TXIM = record end; PXIC = ^TXIC; TXIC = record end; ----------------- END ------------------ I've got them redefined a bit, including a few X<whatever> methods so I could use them more easily. -------------- [as in fpGUI] ------------- TXIC = record dummy: Pointer; end; PXIC = ^TXIC; TXIM = record dummy: Pointer; end; PXIM = ^TXIM; ------------------- END ------------------ // redefines of Xlib functions function XmbLookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar; len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external; function Xutf8LookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar; len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external; Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Felipe Monteiro de Carvalho
to Graeme Geldenhuys: In the xlib.pp unit the following types are defined. How are you supposed to work with a…
Graeme Geldenhuys wrote
In the xlib.pp unit the following types are defined. How are you supposed to work with a record structure that contains nothing? Does it the act like a Pointer type?

It's an opaque structure. You know it's a record, but you don't know what is inside it =)

An encapsulation techinique common in the c world.

In the end always a pointer to the structure will be used (wither by really using a pointer or a var parameter), and it is not created or released on your side of the program, so you don't need to know it's contents or size or anything else.

Felipe Monteiro de Carvalho

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
It's an opaque structure. You know it's a record, but you don't know what is inside it =)

Lovely!! That idea can only come from a C developer. :) The reason Object Pascal is my preferred language - a lot less ambiguous.

In the end always a pointer to the structure will be used (wither by really using a pointer or a var parameter), and it is not created or released on your side of the program, so you don't need to know it's contents or size or anything else.

Well, XOpenIM() and XCreateIC() functions returns or takes the record structure, not a pointer to the structure. This is what confused me, because if I don't know what is inside the structure, how do I know if it was successfully created? Hence the reason I redefined the XOpenIM() and XCreateIC() functions to take pointer types to TXIM and TXIC. I can then test the pointer returned to see if the function call was successful or not. See example below.

Is there another way of handling this and testing if such functions where successful?

  // for correct keyboard handling
  InputMethod := XOpenIM(FDisplay, nil, nil, nil);
  if InputMethod = nil then
    <raise some exception here...>
  InputContext := XCreateIC(InputMethod, [XNInputStyle, XIMPreeditNothing or
      XIMStatusNothing, 0]);
  if InputContext = nil then
    <raise some exception here...>

Regards,
- Graeme -

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

Reply by email