testreg.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {=================================================================
  2. TestReg.pp versión 1.2 12/02/2002
  3. Copyright (C) 2000-2002 by Luis Digital ([email protected])
  4. TestReg pone en prueba y sirve de ejemplo para TRegistry.
  5. Este es software libre bajo la licencia GNU/GPL.
  6. Ver COPYING.FPC y COPYING incluidos con este programa.
  7. Este programa es distribuido esperando que sea útil,
  8. pero SIN NINGUNA GARANTIA.
  9. =================================================================}
  10. Program TestReg;
  11. {$mode objfpc} {$H+}
  12. Uses registry, SysUtils;
  13. Const
  14. SInteger = 'Integer';
  15. SBinaryData = 'Binary';
  16. SBoolean = 'Boolean';
  17. SCurrency = 'Currency';
  18. SExString = 'ExpandString';
  19. SDate = 'Date';
  20. STime = 'Time';
  21. SDateTime = 'DateTime';
  22. SString = 'String';
  23. SFloat = 'Float';
  24. IntVal = 321;
  25. FloatVal = 123.456;
  26. CurrencyVal = 456;
  27. BoolVal = False;
  28. StringVal = 'This is a normal string';
  29. SExpandVal = 'This is an expand string: "%SystemDir%"';
  30. Var
  31. I: Integer;
  32. SubKey: String;
  33. B : Boolean;
  34. F: Double;
  35. C : Currency;
  36. S : String;
  37. BinData: Array [0..15] of Byte;
  38. D : TDateTime;
  39. DateVal,TimeVal,DateTimeVal : TDateTime;
  40. Begin
  41. With TRegistry.Create do
  42. Try
  43. RootKey := HKEY_CURRENT_USER;
  44. SubKey := '\Software\FPC\testreg';
  45. CreateKey(SubKey);
  46. If Not OpenKey(SubKey,False) then
  47. Writeln('Could not open key: ',SubKey)
  48. else
  49. begin
  50. Writeln('Writing data');
  51. WriteInteger(SInteger, IntVal);
  52. For I:= 0 To 15 Do
  53. BinData[I] := I;
  54. WriteBinaryData(SBinaryData,BinData,SizeOf(BinData));
  55. WriteBool(SBoolean, BoolVal);
  56. WriteCurrency(SCurrency, CurrencyVal);
  57. WriteFloat(SFloat, FloatVal);
  58. WriteExpandString(SExString,SExpandVal);
  59. WriteString(SString,StringVal);
  60. DateVal:=Date;
  61. WriteDate(SDate, DateVal);
  62. TimeVal:=Time;
  63. WriteTime(STime, TimeVal);
  64. DateTimeVal:=Now;
  65. WriteDateTime(SDateTime, DateTimeVal);
  66. Writeln('Reading data');
  67. I:=ReadInteger(Sinteger);
  68. If (I<>IntVal) then
  69. Writeln('Read Integer differs: ',I);
  70. FillChar(BinData,SizeOf(Bindata),0);
  71. I:=GetDataSize(SBinaryData);
  72. If I<>16 then
  73. Writeln('Size Binary Data differs: ',I)
  74. else
  75. begin
  76. ReadBinaryData(SBinaryData, BinData,I);
  77. For I:=0 to 15 do
  78. If BinData[i]<>I then
  79. Write('Binary Data byte ',i,' differs : ',BinData[i]);
  80. end;
  81. B:=ReadBool(SBoolean);
  82. If (B<>BoolVal) then
  83. Writeln('Boolean value differs : ',B);
  84. C:=ReadCurrency(SCurrency);
  85. If (C<>CurrencyVal) then
  86. Writeln('Currency value differs: ', C);
  87. S:=ReadString(SString);
  88. If (S<>StringVal) then
  89. Writeln('Read String differs: "',S,'"(',Length(s),')<>"',StringVal,'"(',length(StringVal),')');
  90. D:=ReadDateTime(SDateTime);
  91. If (D<>DateTimeVal) then
  92. Writeln('Read DateTime differs : ',D);
  93. D:=ReadDate(SDate);
  94. If (D<>DateVal) then
  95. Writeln('Read Date differs : ',D);
  96. D:=ReadDateTime(STime);
  97. If (D<>TimeVal) then
  98. Writeln('Read Time differs : ',D);
  99. F:=ReadFloat(SFloat);
  100. If ((F-FloatVal)>1e-4) then
  101. Writeln('Read Float differs: ',F);
  102. If Not DeleteValue(SFloat) Then
  103. Writeln('Error: could not delete float value');
  104. CloseKey;
  105. SubKey:='\Software\fpc\testreg2';
  106. Createkey(SubKey);
  107. If Not DeleteKey(SubKey) Then
  108. Writeln('Error: could not delete key',subkey);
  109. end;
  110. Finally
  111. CloseKey;
  112. free;
  113. end;
  114. End.