Recent

Author Topic: From Delphi to Lazarus, GetModuleHandle function (and others?) missing.  (Read 13820 times)

dodgeydave

  • New Member
  • *
  • Posts: 17
  • PM me if needed.
Hi.

Using Lazarus V1.2.4 32 bit, with FPC 2.6.4, on Win7(64 bit)    Dual monitor, if that makes any difference.

I have a minor issue, when I start Laz', and load a project that was converted from Delphi(7).

Neither the source editor pane, nor the form show up, and I can't find a way to bring them into view (not even the "center lost window" item under the "Window" menu seems to work in this case, though it does with the demo's.)

The PC is a laptop, though I use an external (second "large") monitor and the "extended desktop" feature, where I have the Lazarus IDE in all it's glory, with browser, email, IRC etc on the lappy's main screen.

The only sure fire way to get the editor up, is to do a blind compile or build, but only when it finds an error does the editor pane then appear.    Then I can one by one bring the other units into view, also the "View, Toggle Form/Unit (F12)" will work to bring the form into view, but that then grey's itself out becoming unusable.

This is a simple single form program, with one main unit, plus a couple of utility units.

I can for now live with the above, though it's an annoyance to say the least.


I also have this code snippet.

Code: [Select]
Function GetFilePath (ApplicationFileName: String): String;
Var Buffer: Array[0..255] of Char;
    AppFileName: Array[0..15] of Char;
Begin
     Try
       StrPLCopy(AppFileName, ApplicationFileName, 15);
       GetModuleFileName(GetModuleHandle(AppFileName), Buffer, SizeOf(Buffer));
//  The line above errors with "Identifier not found, for both GetModule*** call's".

       Result := ExtractFilePath(StrPAS(Buffer));
     Except on exception do
       Result := 'Error';
     end;
end;

GetModuleFilename and GetModuleHandle cause a fatal compile error.   (GetModuleFilename because GetModuleHandle is not found I guess.)

The code (the entire app in fact) works fine under Delphi7(32 bit) even on this Win7/64 box, as does the original Delph1 version on XP!   (It's a small app I wrote way back, to get a screen dump from a Tektronix portable 'scope.)

I'm using it to fight my way into Lazarus, as I in the future I'd like to make as many of my home grown tools and tricks cross platform if I can.   (Mostly, tools and utilities that talk with and control specialized hardware via RS232 etc.)

As Windows doesn't have a "grep" tool (and all the downloadable ones are on blocked sites from here, thanks to IT/ISP issues) nor are the Laz sources at my disposal (for similar reasons) how do I find what to add/change in the unit's "Uses" list, so I can use those calls, or equivalents?   (I'm guessing there is an alternative, but it's not in the same system unit name Delphi used.)

I have poked about the forum, and wiki, and though I can find some reference to the above, I can't find out what to add to the "Uses" list.    D7, from memory, if you right clicked or something, it'd tell you what unit the identifier was specified in.    I have to say I dislike "forums" and find Wiki's often incomplete.

There are similar issues with GetPrivateProfileString, used with .ini files.   But I'll probably change to using TXMLPropStorage, to ease the cross-platform idea I have.


I've tinkered around with Lazarus for a while, but this is the first time I've tried to do anything "Significant" with it, bringing old code that is mine to re-use, up to date and future proofing it.

Brickbats/bouquets welcome.

Regards.

DaveB (antiquecoder on the IRC, based in the UK.)

Who let the smoke out?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
GetModuleFilename is in the Windows unit.
However, don't reinvent the wheel.
All you need is
Code: [Select]
uses sysutils, forms;

... := ExtractFilePath(Application.ExeName);

which is cross-platform, and not Windows-dependent.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
What do you mean the Laz sources not at your disposal?
They are included in the installation package.

About showing the editor, try opening a source file from project manager or from File -> open.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

dodgeydave

  • New Member
  • *
  • Posts: 17
  • PM me if needed.
Thanks guys.

HowardPC:
Remember, the original of this program was created way back with Delphi 1, hence the convoluted way to find the file path from the .exe name...  Thanks for the hint.

JuhaManninen:
Re the sources for Lazarus.  They do not appear to come as standard with a windows automated install, or if they do, they do not get installed by default.   If they are, they are not in an obvious place (to me anyway.)    In any case, on this machine, even with the sources, I do not have a Grep tool available to me (yet) to search through them.

I've yet to bite a bullet and go for an install on Linux or BSD.   I can imagine (as is often the case with open source software) that the sources do get installed in that case.

Best Regards.

DaveB.   Nearly home time, but first, a gripe to our masters for shipping us some dead stuff, supposedly "as new"!
Who let the smoke out?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Sorry - I'm not up to speed with this topic, but I did notice...
Quote
In any case, on this machine, even with the sources, I do not have a Grep tool available to me (yet) to search through them.
Well, you have Lazarus - use the menu, "Search" - "Find in Files".  I do an awful lot of hunting with that :-)
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re the sources for Lazarus.  They do not appear to come as standard with a windows automated install, or if they do, they do not get installed by default. If they are, they are not in an obvious place (to me anyway.)

C:\lazarus is quite an obvious place. If the sources are not there then you have done something strange during the install.

Quote
In any case, on this machine, even with the sources, I do not have a Grep tool available to me (yet) to search through them.

Did you try the "Find in Files" as Mike.Cornflake suggested?

Quote
I've yet to bite a bullet and go for an install on Linux or BSD.   I can imagine (as is often the case with open source software) that the sources do get installed in that case.

If you like to study the sources and their commit history, I can recommend trunk, the development version. You can use SVN or Git to get it.
  http://wiki.freepascal.org/Getting_Lazarus#Getting_Lazarus_SVN_development_version
  http://wiki.freepascal.org/git_mirrors
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

dodgeydave

  • New Member
  • *
  • Posts: 17
  • PM me if needed.
Morning.

To Mike.Cornflake:
Thanks for that pointer.  It's not the quickest on this core i3 box (even with 4G of RAM, I'll find more to shove in sometime I think) but it does seem to be working.  Thanks again.

To JuhaManninen:
As you may have read above.  I have now!  :D


Ah...   The search I started a few minutes ago has ended.    The results window is hidden by default (known local IT policies screwing with me than anything wrong with Lazarus I think, so I had to use task mangler to bring the result window to the foreground.)

Now, I see there is a source tree from the FPC\2.6.4 path, and 20+ hits in there, so something to go and explore.  ;)


Don't get me wrong, I like Lazarus and what it stands for, also the philosophy of "open source" code (and hardware!)   But I always find the documentation of such to be relatively poor in detail and often not fully up to date, else why would anyone have to ask here on the list?   (No reply needed thanks!)

(Has to be said, I'm sometimes as guilty in that respect with what I create here!, so pot and kettle etc.)

Thanks for the pointers guys, it is a great help.

73.

DaveB
Who let the smoke out?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Don't get me wrong, I like Lazarus and what it stands for, also the philosophy of "open source" code (and hardware!)   But I always find the documentation of such to be relatively poor in detail and often not fully up to date, else why would anyone have to ask here on the list?   (No reply needed thanks!)
And yet, I'm going to reply :)  You are correct that at times the documentation is lacking.  But at other times the documentation is superb.   As you're new to Lazarus/FPC, so here's a list of available documentation for you to use:

*  FPC Manuals:  http://www.freepascal.org/docs-html/  (These are at times simply excellent)
(Depending on you got your Lazarus, these may also be available as CHMs within your Lazarus folder "Lazarus\docs\chm")   Context help (F1 with a keyword selected) may or may not work for you.  Not functionality I use as I dive into the source code more often than not...

*  Lazarus Wiki: http://wiki.lazarus.freepascal.org/Main_Page  (I'd take the time out to familiarise yourself with this resource.  Many developers (myself included) write documentation for their packages in this wiki before producing any distributable documentation.  It's a community wiki, so once you've found yourself away around, feel free to create an account there yourself and make corrections (lazarus/fpc is a moving target), add code snippets/examples where applicable, or even entirely new content - it all helps)

You've now found the source code.  Consider this the ultimate documentation on how the code is supposed to work :)  You've got *everything* there.

While Delphi VCL compliance is not guaranteed, significant efforts have been made in this regard.  Consequently most general Delphi documentation is also useful.

These Forums: (Massively useful)
Mailing Lists (see links on left):  Also massively useful, though personally I'd be happier if most "How do I?" questions get asked here.  Easier to search...

There's plenty more out there as well.  Hope this helps, and belated Welcome :)

(Has to be said, I'm sometimes as guilty in that respect with what I create here!, so pot and kettle etc.)
*cough* Me too :)
« Last Edit: July 03, 2014, 10:35:14 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Neither the source editor pane, nor the form show up, and I can't find a way to bring them into view (not even the "center lost window" item under the "Window" menu seems to work in this case, though it does with the demo's.)
I usually go to project inspector, double click a pas file and the source editor shows. Yes, center lost window may help as well..
If it's a form, pressing F12 will show the form editor?
Do you see the Source in the Window menu? If yes, it's indeed probably a size/position issue..

As Windows doesn't have a "grep" tool (and all the downloadable ones are on blocked sites from here, thanks to IT/ISP issues) nor are the Laz sources at my disposal (for similar reasons) how do I find what to add/change in the unit's "Uses" list, so I can use those calls, or equivalents?   (I'm guessing there is an alternative, but it's not in the same system unit name Delphi used.)
Apart from the earlier suggestions, you should have a grep installed by Lazarus... on my Lazarus 1.2.4 it's in
C:\Lazarus\fpc\2.6.4\bin\i386-win32\

I have poked about the forum, and wiki, and though I can find some reference to the above, I can't find out what to add to the "Uses" list.    D7, from memory, if you right clicked or something, it'd tell you what unit the identifier was specified in.
You may have some luck with Source/Add unit to uses section which at least lets you see a lot of (all?) available units... though I'm sure there must be better solutions...

I have to say I dislike "forums" and find Wiki's often incomplete.
Share the same though better an incomplete Wiki than no info at all... e.g. the debugging info Martin_fr has put on the wiki is IMO very useful... (though unrelated to this subject).
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Ah...   The search I started a few minutes ago has ended.    The results window is hidden by default (known local IT policies screwing with me than anything wrong with Lazarus I think, so I had to use task mangler to bring the result window to the foreground.)

Here searching all Lazarus sources takes ~ 3 seconds, after the initial slower search when OS caches the file system. My CPU is slower than yours.
If you have FPC sources under the same dir then it takes longer but surely no more than 10 - 15 seconds.
Linux is a little faster but Windows is not bad either nowadays.

You have something fuzzy going on there. Did you install to a network drive, or external USB drive?
A virus scanner should not slow down text searches so much. (?)

The window visibility issues sound strange, too. I hope you did not install AnchorDocking package. It it not good yet. Use it only after you are otherwise familiar with the IDE.
You may have screwed your local config somehow. Please try deleting it and start with a clean default config.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

dodgeydave

  • New Member
  • *
  • Posts: 17
  • PM me if needed.
Hi again.

To BigChimp:
Grep.exe found where you described, and it works of course.  Thanks.

I'm still feeling my way arround the IDE, but keep getting panes missing when I have to exit and restart for some reason (not Laz' crashes, but other PC/IT/Management reasons that are beyond comprehension.)

If I just close Lazarus, without first closing all, then when Lazarus is next launched, it does all come back OK.   It's just when opening a save project that the source and form editors are missing from view.   And, only projects I create from new!...

Incomplete wiki's.  It depends what's missing of course!  :)

Thanks for the pointers.


To JuhaManninen:

This machine was blindingly fast when we first had it, but since "IT" have been meddling, installing more and more "stuff" to make us "safer" it's getting slower and slower.   Just the booting from cold can take 5 minutes, plus the OS and it's baggage uses over 2G of the 4G of available physical RAM!..

Mostly, it's AV, DNS proxies, and similar CPU sucking tools.   I don't get a choice sadly, but the time is coming when my password cracking CD will come out, probably the next time I'm traveling for work and I can't get it to connect to hotel wifi or similar for work needs.


Anyway...  Good News People!...    Re my conversion to Lazarus...

My 'scope screen dump program is now compiling and running as intended, built with Lazarus, so real progress made.  :D

Stages 1 and 2 complete.

1: Importing the (ancient) code.

2: Getting it to build and run "as much as is" for now.   The original .exe was about 400k.  The new version, with no debug code linked in, is some 1.7Meg.  (Sign of the times I guess...)   I'll no doubt be reading up on optimizations for speed or size in the near future.

Stage 3 to commence next.
Tidy and re-document the code removing the stuff that is no longer used nor needed.   (Yes, I have original backups.)

Then Stage 4:
To rewrite the RS232 unit code, to use the LazSerial tool, releasing the program from the commercial/proprietary "WSC4D" serial communications DLL.   Good though it is, it's not Open Source.  (Though I do have the interface sources, the license prevents disclosure, plus the sources for the DLL itself are not supplied.)

I have used TComPort under Delphi, so I know my way around it somewhat, and have already got the fake GPS emulator built and running, so plenty to work from.

Once that is done, many other hardware diagnostic tools and software gadgets I have, will be ported over.

Regards to All.

DD (aka antiquecoder)
Who let the smoke out?

snorkel

  • Hero Member
  • *****
  • Posts: 817
For serial port stuff you can use the Synapse library.

http://www.ararat.cz/synapse/doku.php/start
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

 

TinyPortal © 2005-2018