Sign in Join

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

Mailing lists / lazarus / 2011-08

fpGUI Widget Type: TTimer fix

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Schnell

(using Linux X86 32 Bit):

Initiating TTimer with fpGUI Widget Type issues a Range check error: Project eventtest raises exception class 'RunError(201)'

line 153 is

Result := PtrInt(Timer);

PtrInt in fact is "LongInt".
When stepping my example the value for the Timer variable is $B761AA00. So the Longint will be negative and as THandle is PtrUInt which again is DWord, a range check exception is raised.

Changing the line to

Result := THandle(Timer);

makes the Timer work in my example

I don't know if this is appropriate for all Archs....

-Michael

Reply by email

Unknown author
to Michael Schnell
Michael Schnell wrote 27 lines
(using Linux X86 32 Bit): Initiating TTimer with fpGUI Widget Type issues a Range check error: Project eventtest raises exception class 'RunError(201)' line 153 is Result := PtrInt(Timer); PtrInt in fact is "LongInt". When stepping my example the value for the Timer variable is $B761AA00. So the Longint will be negative and as THandle is PtrUInt which again is DWord, a range check exception is raised. Changing the line to Result := THandle(Timer); makes the Timer work in my example I don't know if this is appropriate for all Archs....

I think

  Result := PtrUint(Timer);

is better and safer. THandle has a 'windows-only' ring to it.

Michael.

Reply by email

Felipe Monteiro de Carvalho
to Unknown author
> line 153 ?is

line 153 of which files?

Show quoted text 5 lines
I think ?Result := PtrUint(Timer); is better and safer. THandle has a 'windows-only' ring to it. From LCLType.pas:
  {$ifndef WINDOWS}
  THandle = type PtrUInt; // define our own, because the
SysUtils.THandle = System.THandle is a longint
  HANDLE = THandle;
  PHandle = ^THandle;

Although there is also:

unit WSReferences;
...
type
  // use TLCLHandle instead of THandle since THandle = longint under 64bit linux
  TLCLHandle = PtrUInt;
  PLCLHandle = ^TLCLHandle;

The comment seams to ignore the existence of LCLType.THandle.

Felipe Monteiro de Carvalho

Reply by email

Michael Schnell
to Unknown author: I think Result := PtrUint(Timer); is better and safer. THandle has a 'windows-only' ring…
I think Result := PtrUint(Timer); is better and safer. THandle has a 'windows-only' ring to it.

I suppose you are correct, but the source code of the function in fact is

function TFpGuiWidgetSet.CreateTimer(Interval: integer; TimerFunc:
TWSTimerProc): THandle;
var
   Timer: TFPGUITimer;
begin
   Timer := TFPGUITimer.Create(Interval, TimerFunc);
   Result := THandle(Timer);
end;

So if appropriate, it would be better/necessary to eliminate the THandle type in a more general context.

-Michael

Reply by email

Michael Schnell
to Unknown author: I think Result := PtrUint(Timer); is better and safer. THandle has a 'windows-only' ring…
THandle has a 'windows-only' ring to it.

I'm not a native speaker but AFAIK, a "handle" is just something you can grasp some object at.

So a handle (type THandle) might be something to denote a certain object without forcing to have it a known memory address (such as Pointer or a TObject sibling would need) .

Thus I feel that it might not be such a bad idea to use THandle in a non-windowish Widget Type code.

-Michael

Reply by email