Menu
Search




Articles & Documents

Close Tutorials

Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
22 Subscribers
CPDB.Net

Friends News
Visits

   visitors

   visitors online

Webmaster - Infos
forum.gifForum - ppCompiler - Topic #27

Forum - Forum
ppCompiler - ppCompiler


active  Topic # 27  Procedure TimSecondsToDateTime

19/09/2010 @ 15:23
by dearjohn

Anonymous



I can not handle this procedure, in my opinion the following should work to get the month, but the last line "m:=MyDateTime.month;" fails compiling with error: unexpected "." What's wrong with it, MyDateTime is of type DateTimePtr?

Const
SYSTRAP = $4E4F;
sysTrapTimSecondsToDateTime = $A0FC;

Type
UInt8  = -128..127;
Uint16 = 0..65535;
UInt32 = integer;

  DateTimeType = record
    second: UInt16;
    minute: UInt16;
    hour: UInt16;
    day: UInt16;
    month: UInt16;
    year: UInt16;
    weekDay: UInt16; // Days since Sunday (0 to 6)
  end;

  DateTimePtr = ^DateTimeType;

var
MyDateTime : DateTimePtr;
m          : integer;

(* ===== TIME =====*)
function  TimGetSeconds:UInt32; inline(SYSTRAP,$A0F5);
function  TimGetTicks:UInt32; inline(SYSTRAP,$A0F7);
procedure TimSecondsToDateTime(seconds: UInt32; dateTimeP: DateTimePtr);
inline(SYSTRAP, sysTrapTimSecondsToDateTime);

begin
TimSecondsToDateTime(TimGetSeconds,MyDateTime);
m:=MyDateTime.month;
end.

 

Thanks in advance. Reinhard.

Write to dearjohn   Post an answer  Top
Answer n° 1
--------
23/09/2010 @ 17:44
by Philippe

Anonymous

visitor
The error is because you try to access to a field for a non record type. The "MyDateTime" is a pointer, not a record.
To fix the problem in the spirit of Pascal Language, you should define :

procedure TimSecondsToDateTime(seconds: UInt32; var dateTimeP: DateTimePtr);
inline(SYSTRAP, sysTrapTimSecondsToDateTime); // with the secont parameter passed by reference with the keyword var

Then the "MaDateTime" should be declared as a DateTimeType, not a pointer:
var MyDateTime : DateTimeType;

And then all should go fine.

If you prefer keep the "MyDateTime" variable as a pointer, it must be allocated before being used, with

new(MyDateTime);

And then, access to the "month" field is done by

m:=MyDateTime^.month;

Philippe.
Write to Philippe   Post an answer  Top
Answer n° 2
--------
23/09/2010 @ 18:26
by Philippe

Anonymous

visitor
There remainds an error in the definition of TimSecondToDateTime in my previous message. With the keyword var, the second parameter is of type DataTimeType.

procedure TimSecondsToDateTime(seconds: UInt32; var dateTimeP: DateTimeType);
inline(SYSTRAP, sysTrapTimSecondsToDateTime); // with the secont parameter passed by reference with the keyword var
Write to Philippe   Post an answer  Top
Answer n° 3
--------
24/09/2010 @ 10:42
by dearjohn

Anonymous

visitor

I tried it both, with and without pointer, and both solutions are working properly!

Thanks a lot.

Reinhard.

Write to dearjohn   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 




^ Top ^