Recent

Author Topic: Build failure  (Read 2877 times)

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #45 on: June 18, 2025, 04:11:04 am »
    I removed all references to lazutilsstrconsts out of my project, including the .ppu and .o references to it. I installed
Lazarus 4.0, compiled the project and attached is the result. At least it has nothing to do with Utf8!
    I feel optimistic but I don't know if that feeling is justified.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11433
  • Debugger - SynEdit - and more
    • wiki
Re: Build failure
« Reply #46 on: June 18, 2025, 08:49:29 am »
The more important bits are the warnings.

It shows that
- indeed you (probably don't have a copy in your project)
- but somehow units from 2 different lazarus installations are getting mixed
  c:\lazarus
  c:\Users\Art|Desktop\lazarus2

So there may be something wrong with the "packages" used by your project. But I also suspect that there may be wrong settings in the "path" page of "project options"

Which of the 2 Lazarus are you using for this build?
You can (for testing) rename the folder with the other one (and later change it back).

Though that will (probably) not fix the problem it will just change the error. Slight change that the error will then be more meaningful (at least to some of of us who have replied)



Lets start with a look at the "Path" settings.

If you can attach the "lpi" file of your project.

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #47 on: June 18, 2025, 11:57:18 am »
    BIG NEWS! I think that I may be almost there. I got rid of the duplicate identifiers, documents etc., uninstalled Lazarus 2.2.6,
removed all references to Utf8 and did some other stuff.
    THE PROGRAM ALMOST COMPILES with only one error message holding things up. The error occurs in the code shown below and
in the attached screenshot.
    The purpose of this code is to get the serial number of the monitor.
    It appears to work fine on the old machine but not on the new machine.
    Please look at it and see if you can tell what it needs or if you know another way to get the serial number.
    Thank you. This bug is the only thing that prevents a successful compilation.
    If this thing compiles then I will yell loudly, even if the neighbors complain and I will do a few other things too. My fingers are crossed.

Code: Pascal  [Select][+][-]
  1. function GetSerialNumber(var ASerial: WideString): Boolean;
  2. const
  3.   FlagForwardOnly = $00000020;
  4.   WMIClass = 'Win32_PhysicalMedia';
  5.   WMIProperty = 'SerialNumber';
  6. var
  7.   SWbemLocator, WMIService: Variant;
  8.   WbemObjectSet, WbemObject: Variant;
  9.   EnumVarinat: IEnumvariant;
  10.   SQL: WideString;
  11. begin
  12.  Result := False;
  13.   SWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  14.   WMIService := SWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
  15.   SQL := WideString(Format('SELECT %s FROM %s', [WMIProperty, WMIClass]));
  16.   try
  17.     WbemObjectSet := WMIService.ExecQuery(SQL, 'WQL', FlagForwardOnly);
  18.     EnumVarinat := IUnknown(WbemObjectSet._NewEnum) as IEnumVariant;
  19.     if EnumVarinat.Next(1, WbemObject, nil) = 0 then
  20.     begin
  21.       if not VarIsNull(WbemObject.Properties_.Item(WMIProperty).Value) then
  22.         ASerial := WbemObject.Properties_.Item(WMIProperty).Value;
  23.     end;
  24.     WbemObject := Unassigned;
  25.     Result:= True;
  26.   except
  27.     on E: Exception do
  28.       ShowMessage('Cannot get serial number: ' + sLineBreak + E.Message);
  29.   end;
  30. end;




user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #48 on: June 18, 2025, 12:23:11 pm »
    Man, if this works (re: previous post) then you guys did it. Not me. You.
    I will follow up on what I said in the jobs section if this works out.
    Maybe I'm getting my hopes up. If so then this is cruelty beyond description.

dbannon

  • Hero Member
  • *****
  • Posts: 3404
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Build failure
« Reply #49 on: June 18, 2025, 12:33:12 pm »
Sigh ....

user5, people want to help you with these error message but you have to tell us what they are !

You have shown us two copies of the code that generates the error (good) but not the error generated by the compiler when it hit that line of code. You will see that error message when hovering the mouse over the red blob to left of the offending code and it also appears in the messages window.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #50 on: June 18, 2025, 02:37:10 pm »
    Okay. The attached picture messages1.png is the displayed messages that you requested.
    The code shown in the code section is what I did as a test. I made the error lines be inert to see if the program would compile.
    However, when I tried to compile the program with the inert code, the result are the error messages shown in messages2.png.
    The compiler goes nuts if I try to remove that function and I've never seen this before. I don't know what the messages in messages2.png mean.

Code: Pascal  [Select][+][-]
  1. Result := False;
  2.   SWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  3.   WMIService := SWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
  4.   SQL := WideString(Format('SELECT %s FROM %s', [WMIProperty, WMIClass]));
  5.   try
  6.     WbemObjectSet := WMIService.ExecQuery(SQL, 'WQL', FlagForwardOnly);
  7.     EnumVarinat := IUnknown(WbemObjectSet._NewEnum) as IEnumVariant;
  8.     //if EnumVarinat.Next(1, WbemObject, nil) = 0 then
  9.     //begin
  10.       //if not VarIsNull(WbemObject.Properties_.Item(WMIProperty).Value) then
  11.         //ASerial := WbemObject.Properties_.Item(WMIProperty).Value;
  12.     //end;
  13.     WbemObject := Unassigned;
  14.     Result:= True;
  15.   except
  16.     on E: Exception do
  17.       ShowMessage('Cannot get serial number: ' + sLineBreak + E.Message);
  18.   end;




cdbc

  • Hero Member
  • *****
  • Posts: 2245
    • http://www.cdbc.dk
Re: Build failure
« Reply #51 on: June 18, 2025, 02:48:53 pm »
Hi
Is this:
Code: Pascal  [Select][+][-]
  1. if EnumVarinat.Next(1, WbemObject, nil) = 0 then
by any chance line 388 in unit1.pas?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

wp

  • Hero Member
  • *****
  • Posts: 12902
Re: Build failure
« Reply #52 on: June 18, 2025, 04:36:02 pm »
This is what I am doing when navigating through unknown code (and even my own code is "unknown" after a short time...):

In your code which I copied into a small test project, I CTLR+click on the word "Next" in the erroneous line ("if EnumVariant.Next(....)"), and the IDE will open the unit in which it is implemented. This brings me into unit ActiveX to the following code:
Code: Pascal  [Select][+][-]
  1.    IEnumVARIANT = Interface (IUnknown)
  2.      ['{00020404-0000-0000-C000-000000000046}']
  3.      {$ifndef Call_as}
  4.       Function  Next(celt: ULONG; OUT rgVar: OLEVARIANT;  out pCeltFetched: ULONG):HResult;StdCall;
  5.      {$else}
  6.       Function  Next(celt: ULONG; OUT rgVar: OLEVARIANT;  pCeltFetched: pULONG=nil):HResult;StdCall;
  7.      {$endif}
  8.     ...
  9.      End;
  10.  
In current Laz/FPC, the second version of this method is grayed, i.e. not used, and this leads to the conclusion that the first version is in use. Here the last argument must be a ULONG (LongWord), not a pointer as in your code ("nil"). Note also, that it is an "out" parameter, therefore it does not work to replace the "nil" by "0" - introduce a longword variable for it:

Code: Pascal  [Select][+][-]
  1. var
  2.   n: LongWord;
  3. ...
  4.     EnumVarinat := IUnknown(WbemObjectSet._NewEnum) as IEnumVariant;
  5.     if EnumVarinat.Next(1, WbemObject, n) = 0 then
  6.     begin                                      
  7.  

This modification is accepted by the compiler and brings me to the next issue: WbemObject is declared as a variant in your code, but the funtion signature wants it to be an OLEVariant - ok, easily changed. Now the code compiles and returns the same result as the CrystalDiskInfo tool -- see attachment.
« Last Edit: June 18, 2025, 04:37:38 pm by wp »

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #53 on: June 18, 2025, 05:33:13 pm »
    wp, I also tried to use a longword variable though I used var1 instead of n but in either case it still didn't work.
    I ran your code variation and it worked fine but when I put those two changes (n, OleVariant) in the Form1 code
then I again got the error message as shown in message2.png.
    Form1 is the opening page of the program. I don't know what's going on here. I don't know why it works on my
old machine and in you example project but not on my new machine. When I tried to remove the function then again
I got the error message shown in messages2.png.

wp

  • Hero Member
  • *****
  • Posts: 12902
Re: Build failure
« Reply #54 on: June 18, 2025, 05:51:17 pm »
message2.png bringt us back to the LazUtilsStrConsts issue...

I don't know if this already has been mentioned: You must not add any path into the Lazarus units to the project's "Other unit files". Normally, this field is empty, or contains only paths within your project (for example, when you have forms in a separate folder "forms" then, of course, there should be the path "forms" in "Other unit files").

And unlike as proposed by others, I never had to add LazUtilsStrConsts to the uses clause of any of the project units- this is a unit used internally by the LazUtils package. It is only needed if you want to use one of the string constants defined in there.

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #55 on: June 18, 2025, 06:10:57 pm »
    Hold everything. I temporarily removed all the Utf8 stuff from Form1 and removed some more "duplicates" and the result
is that the program compiled!
    It also builds fine and I ran it!
    I will now reinstate the Utf8 stuff and see what happens. I'm not too worried about it since I think that it can all be replaced if necessary.
    I need to check some stuff out and I need to see if the modified program will compile on the old machine but it looks like I'm in business.
    Wowser. I will get back to ya and of course, I say thanks but it sounds inadequate to the occasion!
    This is hard to believe.

user5

  • Sr. Member
  • ****
  • Posts: 414
Re: Build failure
« Reply #56 on: June 18, 2025, 07:42:34 pm »
    The program compiled fine with the Utf8 stuff.
    Interestingly enough, the modified program would not compile on the old machine unless nil is used instead of a var
like n as in your example. Thus, I will have to keep them separate though this is a small price to pay. Also, Variant has
to be used instead of OleVariant. It did compile though.
    I see now that those error messages shown in messages2.png were about the duplicates, not the code. I didn't know
that I had such duplicates nor that new versions of Lazarus are so touchy about 'em.
    This means that I will be able to work on the main program on a machine that's more than twice as fast. It also means
that there's no rush to buy a new computer.
    I just made my second recent donation to the forum for a total of $300.00.
    It's money well spent.
    I know that you would have done it for free but I'm glad on this special occasion to follow through on the offer that I made in the Jobs section.
    What can I say? I didn't think that this was really possible.
    You did it. I couldn't have done it on my own. What a thread!
    This is incredible. Thank you so very much and all praise to Lazarus.

 

TinyPortal © 2005-2018