Recent

Author Topic: [SOLVED] uses Windows gives errors  (Read 983 times)

petevick

  • Sr. Member
  • ****
  • Posts: 392
[SOLVED] uses Windows gives errors
« on: January 23, 2024, 10:43:24 am »
I've added Windows to my uses section as I want to read the registry, but when I compile I get two errors at this line....

Code: Pascal  [Select][+][-]
  1.   bmp := TBitmap.Create;

...the errors are....

Code: Text  [Select][+][-]
  1. unit1.pas(1379,18) Error: identifier idents no member "Create"
  2. unit1.pas(1379,18) Fatal: Syntax error, ";" expected but "identifier CREATE" found

...the uses section for Windows is as follows...

Code: Pascal  [Select][+][-]
  1. {$IFDEF WINDOWS}
  2. uses
  3.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  4.   ComCtrls, Buttons, fileutil, Menus, BCButtonFocus, BCButton, BCTrackbarUpdown,
  5.   BCComboBox, BCLabel, LCLIntf, GraphUtil, LazFileUtils,
  6.   Contnrs, LCLType, BCTypes, process, jwatlhelp32, WinDirs, Windows;
  7. {$ENDIF}
  8.  

....if I remove the Windows uses there are no errors. I've had no problems with this particular section of the code until I added Windows uses.

I'm totally stumped by it, and I guess using the Windows uses is the only way to read registry keys.  :-\
« Last Edit: January 23, 2024, 12:04:11 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.4, FPC 3.2.2

TRon

  • Hero Member
  • *****
  • Posts: 3141
Re: uses Windows gives errors
« Reply #1 on: January 23, 2024, 11:02:31 am »
....if I remove the Windows uses there are no errors. I've had no problems with this particular section of the code until I added Windows uses.
Windows unit has it's own declaration for f.e. TBitmap. Prefix either your use of TBitmap with graphics (e.g. graphics.TBitmap) or in case you wish to use a windows specific declaration of TBitmap with windows.TBitmap.

Quote
I'm totally stumped by it, and I guess using the Windows uses is the only way to read registry keys.  :-\
The last included unit's declarations take precedence over declaration made in earlier included units.

Alternatively you can move your windows uses clause to before that of the graphics unit (which variable of type TBitmap you have to prefix then depends on the order of included units).


PS: Note that you do not have to use the windows unit yourself in case you wish to access the registry. There are abstractions for that such as fcl-registry.
« Last Edit: January 23, 2024, 11:10:09 am by TRon »
All software is open source (as long as you can read assembler)

petevick

  • Sr. Member
  • ****
  • Posts: 392
Re: uses Windows gives errors
« Reply #2 on: January 23, 2024, 12:03:53 pm »
.......
PS: Note that you do not have to use the windows unit yourself in case you wish to access the registry. There are abstractions for that such as fcl-registry.
That's the answer. Thanks for your help TRon  ;)
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.4, FPC 3.2.2

 

TinyPortal © 2005-2018