Menu
Recherche




Articles & Documents

Fermer Tutoriaux

Lettre d'information
Pour avoir des nouvelles de ce site, inscrivez-vous à notre Newsletter.
S'abonner
Se désabonner
22 Abonnés
CPDB.Net

Nouvelles des Amis
Visites

   visiteurs

   visiteurs en ligne

Webmaster - Infos
forum.gifForum - ppCompiler - Sujet n°27

Forum - Forum
ppCompiler - ppCompiler


actif  Sujet n° 27  Procedure TimSecondsToDateTime

le 19/09/2010 @ 15:23
par dearjohn

Anonyme



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.

Ecrire à dearjohn   Poster une réponse  Haut
Réponse n° 1
--------
le 23/09/2010 @ 17:44
par Philippe

Anonyme

visiteur
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.
Ecrire à Philippe   Poster une réponse  Haut
Réponse n° 2
--------
le 23/09/2010 @ 18:26
par Philippe

Anonyme

visiteur
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
Ecrire à Philippe   Poster une réponse  Haut
Réponse n° 3
--------
le 24/09/2010 @ 10:42
par dearjohn

Anonyme

visiteur

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

Thanks a lot.

Reinhard.

Ecrire à dearjohn   Poster une réponse  Haut
actif sujet actif   clos sujet clos   Important! Important!   Nouveau Nouveau message   -   Rectifier Rectifier message   Clôturer Clôturer sujet   Remonter Remonter
[]
Catégories de discussion  Forum 




^ Haut ^