Class ”TPage” not found lazarus / 61-Beginners ---------------------------------------------------------------------- CJ · 2021-02-08 19:49 Lazarus Versie# 2.0.10 FPC Version: 3.2.0 SVN revisie 63526 I386-win32-win32/win64 Windows10 Pro N version 2004 Hi, I am new in Lazarus. I try to build a Turbo Pascal V4 project with Lazarus. I have converted the DFM’s in LFM’s with the Lazarus tool. I had to do some little changes like removing the TPage “capitation” property and the “FileEditStyle” property from TOpenDialog. All Forms are displayed correct and compilation is successful but at runtime I get an Exception Notification from the Debugger “Project PCD_PRJ raised exception class ‘EClassNotFound with message Class ”TPage” not found”. How can I solve this? ---------------------------------------------------------------------- lucamar · 2021-02-09 03:48 And try to be more precise, if possible. If it has got DFM forms, etc. it can not be a TURBO PASCAL V4 project, so it's ... what? a Delphi 4 project? ""capitation"?? If you're not precise it makes it more difficult to help you meaningfully. Does the form has a TNotebook or similar multi-page control? If so, does it have pages added at design time (look for "TPage" in the dfm)? Do you still have a Delphi to open the project if it's needed? e.g. To check whether something is or isn't there, etc. And last, but not less, can you share the project so we can do some checks and tests on our own? (if you don't know how, read the wiki page: Forum) ---------------------------------------------------------------------- CJ · 2021-02-10 16:34 The project appears to be a Delphi project. It is in fact the user interface of “32-channel PC dimmer” project from Elektor. The Idea is to remake that user interface. I have the hardware of a 16 channel PC – dimmer still in working condition. I can send the elector article describing the hardware project in a next answer. The Pascal software is included in this post. I tried to rebuild the project with Lazarus because I don’t have any other means while other Delphi IDE SW is very expensive. TPage “capitation” property must be “Caption” sorry for that mistake. The TPage(s) is (are) part of a Notebook control. The TPages are also in the DFM files (ACTION, INSOPT and PC-DIMMER). If I run the project from the converted DFM’s I got “Component Class TPage. Error reading TPage.Caption: Unknown property “Caption”. So I removed them and now the Forms are visual and no more read errors. The same for “FileEditStyle” property from TOpenDialog. Removing the TPage component is not direct a solution. For example the ACTION form has 3 TPage components. When I remove them the underlying Menus are all transparently visible over each other ---------------------------------------------------------------------- CJ · 2021-02-10 16:37 Here the Elektor article ---------------------------------------------------------------------- wp · 2021-02-10 17:33 Quote from: Christiaan Janssens on February 10, 2021, 05:34:19 pmThe Pascal software is included in this post. You are providing the code already modified by you. This makes it very difficult for us to help. Please post the original Delphi code. ---------------------------------------------------------------------- howardpc · 2021-02-10 20:56 I think the main problem is in the ACTION unit which has a Notebook. The converter did not get the Delphi to Lazarus notebook conversion quite right, and the lfm has unnamed notebook pages that show as :TPage in the object inspector. I've never had much success editing lfm files in Lazarus because the resource data is cached, and because of the tight Designer/Editor integration which ensures the .pas and .lfm files are always in sync Lazarus usually undoes manual editing, and also can produce IDE crashes. You can try editing the ACTION.lfm outside of the IDE. But you may have the tedious job of rebuilding the entire unit from scratch. ---------------------------------------------------------------------- wp · 2021-02-10 21:55 That's a good hint, Howard, which brought me back into the game. The issue with the ACTION unit can be solved by adding a new TNotebook to this form and then deleting it again. The converter obviously missed some detail which is fixed when the component is added in Lazarus. Next issue is in the INSOPT unit. When the InsOptDlg is created the application aborts. There is another Notebook, but looking at it in the object tree I see that it has no pages, there are only 4 groupboxes which were inserted immediately into the notebook. Obviously the notebook does not like this... I don't know whether this was like this in the first place or whether this was created by faulty automatic or manual conversion. Anyway, it can be fixed. Rightclick on the Notebook1 in the object tree and add 4 pages. Then select the Groupbox2 node underneath the Notebook1 node, right-click and select "Change parent". Select "Page1" as new parent. Repeat with the other groupboxes and assign each one to its own page. Now the application starts without error. Of course you must check whether the assignment of groupboxes to pages is correct maybe by running the original exe or by loading the (original) code into Delphi. If you don't have Delphi, the Community Edition is free. I forgot to mention that there is also a message that an event handler must be removed - I think this is about the ChScroll handler because this is the source of the next error: When you run the program and try to scroll one of the scrollbars the application will crash with a SIGSEGV. This is because the LCL seems to have a different signature for the parameters of this event. To fix it create a new OnScroll event handler, copy the code of the old ChScroll procedure into the new handler, delete (or comment) the old handler, rename the new handler to ChScroll and make sure that it is used by every scrollbar. ---------------------------------------------------------------------- CJ · 2021-02-11 13:43 Thanks for the help. I include the original Delphi sources. The changes I made to the sources sent yesterday are related to the missing serial port driver. I commented out all references to the serial communication. The user interface communicates with the HW over a serial link. The original sources did not contain the comportdriver unit. This unit is referenced in the about dialog as: “This program uses a freeware com-port component: TCOMMPORTDRIVER written by M. Cocco Copyright 1997 by M. Cocco. All rights reserved”. In the mean time I found 3 versions of the comport driver on the Internet but this will be subject of another Lazarus adventure. I have included them also in a .zip file. I will first try to repair the Action and Insopt forms. I assume I do this in the Lazarus IDE right? Many thanks ---------------------------------------------------------------------- wp · 2021-02-11 17:22 Thanks for the original source. Here's a log of what I was doing to convert the project to Lazarus manually Unzip everything into a folder "Delphi" and into a folder "Lazarus". The commportdriver goes into a subfolder of each.If you have Delphi, test the project with Delphi: Open the .dpr file from the Delphi folder --> Delphi reports that the CommportDriver is not installed. --> "Ignore all" --> the project loads. Open the PCDimmer unit (this is where the ComPortdriver resides. Unit ComDrv32 has a wavy underscore --> unit not found. Strange, the Comportdriver.zip contains only a ComDrv unit. Rename ComDrv32 to ComDrv as a test. Add the CompPortDriver folder to the search path. I don't want to install the ComPortdriver --> move the line "comport: TCommPortDriver" into the public section of TMainForm. Find the method TMainForm.FormCreate and add the lines to create comport at runtime: comport := TCommPortDriver.Create(self);. Compile --> success. No runtime error. Now we have a working version for referenceNow the hard work with Lazarus: Go to the Lazarus version folder of your project and open one of the dfm files in an external editor (Notepad++). You see that it has a "strange" format, this is because these dfm files in the old binary format. You can use Lazarus to convert them to text format: use menu "Tools" > "Delphi Conversion" > "Convert binary dfm to text lfm + check syntax"; apply this to every dfm file in the project, it will create an equally named .lfm file.Open each pas file in Notepad++, find the line {$R *.dfm} and replace it by {$R *.lfm} (I assume here that you will not use the converted project in Delphi any more).When you have the PCDIMMER.pas file in Notepad++ already take care of the Comportdriver - the Lazarus version possibly will not be able to use it. So let's remove it for the time being. Comment out the unit ComDrv32 in the uses list and comment the line "comport: TCommPortDriver". There are also lines in which the "comport" is used, but the compiler will tell us later. You must also open the PCDimmer.lfm file and delete the block in which comport is defined. Otherwise form streaming will fail here.Rename the project file from PCD_RRJ.DPR to pcd_prj.lpr. Open it in Notepad++. Add "Interfaces" as first unit. Note below that all forms of the project are part of the project. This will be destroyed by the next step and must be restored later.Moment of truth: Open the newly generated lpr file by Lazarus. There is a message saying that the IDE does not know which kind of file the lpr is. Answer "Yes" to say it is a project and select "Project" > "Application". This recreates the Lazarus lpi file. But when you open the Project inspector you see that it does not contain any forms. So, in the Project Inspector, select "Add" > "Add Files From File System". Select PCDIMMER.pas at first because it contains the project's main form. Then repeat and add the other pas files, ABOUT.pas, ACTION.pas, INSMEM.pas, INSOPT.pas and SETNAMES.pas.Before compiling check all units with forms for errors: open ABOUT.pas and press F12 to show the form in the designer - no problem. Now load ACTION.pas, press F12 --> Lazarus writes tons of messages that the class TPage has no property "Caption". Use the Task Manager to kill Lazarus (you will have to repeat this step several time later.) Open ACTION.lfm in Notepad++. The file currently contains for the Notebook pages a construction like this:Code: [Select]    object TPage       Left = 0       Top = 0       Caption = 'Choice'To learn what's wrong open Lazarus again, create a new project, add a TNotebook and some pages. Save. Right- click on the form and select "View source (.lfm)" and see how the notebook page should be stored:Code: [Select]     object Test: TPage     end  This means that there is no caption property, and the caption would be the name in front of the TPage. So, now you can open the ACTION.lfm again in Notepad++ and edit the Page section of the previous example like this:Code: [Select]    object Choice: TPage Make sure to remove the Caption. There are some cases in which the Caption contains spaces and therefore cannot be used as Name of the page - in this case simply drop the spaces. Repeat with all occurences of TPage. Save the lfm file. Repeat with PCDIMMER and INSOPT which are the other forms using a TNotebook.Load the project into Lazarus - there is the endless message again, now about property TNotebook.ParentColor not being found. Open the Notebook-lfms in Notepad++ again and delete the ParentColor lines in each TNotebook block; but there is only one for Notebook1 in PCDIMMER.Other properties to be deleted are OpenDialog.FileEditStyle and SaveDialog.FileEditStyle in PCDIMMER property NotebookLoad the project into Lazarus and try to compile again --> unit PCDimmer, OLECtrls not found. Hmmm... Maybe it's not needed? Comment it out for a test. Luckily it works Next error: unit ACTION, Tabnotbk not found. Yes, the TNotebook is in ExtCtrls in Lazarus. but ExtCtrls is already in the uses list --> simply delete Tabnotbk.Next error: unit Mask not found --> remove it for a test --> ok (This works because Delphi often adds too many unused units by default). Now an important error: in PCdimmer procedure FormClose, "Duplicate identifier Action". This is because we did not yet switch the project to DELPHI compiler mode, in the Lazarus default, objfpc procedure parameters must be different from class properties etc. Open "Project options" > "Compiler options" > "Parsing". In the "Syntax mode" combobox select the item "Delphi (-MDelphi)"In the next compilation attempt the compiler does not find the variable "comport" - ok, we had deleted this one initially. The variable is used in methods "SendData", "FormCreate", "COM1Clicked", "COM2Clicked", "COM3Clicked", "COM4Clicked", "FormClose". Just comment out all usages of the variable "comport".Now compilation succeedsBut when the program runs the "class TPage not found" error occurs. Where does it occur? Open the lpr file and set a break point at the first instruction, run and step through the lpr file --> the error occurs in PCDimmer. Ah - this seems to be that mysterious case where it helped to add a TNotebook to the form and delete it again. --> Yes, it works, but the same procedure has to be repeated with the ACTION and INSOPT units.Now the program runs!But the program at runtime is very wide, and the form contents somehow is truncated... Looking at the controls in the object inspector and the object tree it can be seen that the Notebook is inside a groupbox and both of them are inside their parent with Align = alNone. I would client-align it to let Lazarus take care of the size. So, select the notebook and set its Align to alClient, then press ESC to select its parent, the GroupBox1, and set its Align to alClient, too. I would also set the form's AutoSize to true.Still the form is very wide... In the FormCreate handler there is code to set the width and height - remove these lines, as well as the following  four line "if... then scaleby".Some more steps were required to to fix the form size - unfortunately I did not write down all steps, please experiment on your own. This brings me to the end of this long log. If you take the time to follow these notes step by step you will learn a lot about Delphi-to- Lazarus conversion. I know the automatic converter will be much simpler, but you do not have control over what is happening, and sometimes you'd have to chase errors introduced by the converter (of course in the manual conversion you'll also have to chase errors, now introduced by yourself - but that's the learning experience). Of course, we are not ready. The CommPortDriver is still waiting. Since I don't have such a dimmer I cannot help you and leave this job to you. There's one problem I see: I am afraid that the library that you uploaded is not the correct one because the original PCDimmer needed a unit ComDrv32 which is missing in your zip. And in the original PCDimmer.dfm file the TCommPortDriver sets a property procedure EnableDTROnOpen which does not exist here either. If, in the end, you plan to make your application cross-platform, I'd recommend to carefully study what is happening when the CommPortDriver is involved, and then I'd switch to something like LazSeries or Synaser which are used in many many Lazarus applications. P.S. When running the application and clicking on some buttons there is the issue that some forms contain groupboxes, and they behave differently between delphi and lazarus regarding the client space origin and you must move up all containted controls by some pixels ---------------------------------------------------------------------- CJ · 2021-02-11 22:01 Hi, I was ready to post the results of my actions but I see you have put a lot of effort into trying to solve my problems. Many thanks. I will follow your instructions regarding the make of a Delphi reference version and afterwards do the Lazarus work. This is what I did with your hints of yesterday but it is overruled now with your new instructions: I have changed the ACTION and INSOPT units according the instructions of wp. When I compile and run the same exception class ‘EClassNotFound with message Class ”TPage” not found’. I have include both units.  Hi, I have installed the evaluation version of Delphi 10.4 and tried to compile the pc-dimmer project. It compiles without errors but at run time I got Debugger Exception Notifications telling: Project PCD_PRJ.exe raised exception class EReadError with message ‘Invalid property value’. After continue: Project PCD_PRJ.exe raised exception class EReadError with message ‘Error reading COM1.OnClick: Invalid property value’. The program stops at execution of: Application.CreateForm(TActionDlg, ActionDlg); There is in the files no trace of a COM1.OnClick. The PCDIMMER.PAS unit is the one with commented out all references to the serial communication. Thanks for the good work, Chris ---------------------------------------------------------------------- CJ · 2021-02-12 22:08 Hi, I managed to get the Delphi version work. I had to incorporate the ComDrv into the project because changing the search path (Project/Oprions/Resource Compiler/Directories and Conditionals/include file search path) did not work as I expected. After moving the line "comport: TCommPortDriver" into the public section of TMainForm. And adding “comport := TCommPortDriver.Create(self);” in the method TMainForm.FormCreate And modifying comport.comport  into comport.Port, Compilation was successful. The main form looks different in respect to the original Win95 version but this is a small detail. (I cannot change the colour of the Scrollbar, no Colour property?) However I am very pleased with the good work you did to help me. I have included the working version. I just have to test if the communication works also. I will now start to work with the Lazarus part. ---------------------------------------------------------------------- CJ · 2021-02-16 18:20 Hi, the Delfi project did not work with the CPDrv.pas. Compilation was OK and at run time the interface was working well but there was no communication over the com port with the hardware. However I found the ComDrv32.pas code in https://searchcode.com/codesearch/view/13234384/. So I changed CPDrv in ComDrv32. Compilation direct OK after changing comport.Port into comport.ComPort  in PCDIMMER.pas and YES, now the serial line works. So I tried to do the same with the working Lazarus version. Compilation was no problem but at run time at pcd-prj .lpr line 20 Application.CreateForm(TMainForm, MainForm);  it run into a Debugger Exception Notification “ Project pcd-prj raised exception class ‘RunError(217)’. In File ‘ComDrv32.pas’ at line 657. The reason was in ComDrv32.pas:165-166 FNotifyWnd := AllocateHWnd( TimerWndProc ); I even found a Post about this problem: By Curt Carpenter Re: Where is AllocateHwnd? « Reply #8 on: August 23, 2011, 05:46:47 am » This is a very old thread -- but for future reference by anyone who may try to use AllocateHwnd or DeallocateHwnd in the future: In Lazarus 0.9.30, the source for these two procedures is in the fpc  subdirectory at  ..\source\rtl\win32\classes.pp then classesh.inc. The procedures are there in the code -- but they are only stubs that do nothing except generate a Runerror(217) message. Hence code that uses these procedures will compile alright -- but will fail at runtime with that error message. This is the end of this try to make the Lazarus version work with the serial communication. However I don’t give up easily. In my search for a ComPortDriver I found ComportDriverThread.pas a modified version of ComDrv32. Compilation is not a problem but at compilation of PCDIMMER.PAS at  PCDIMMER.PAS(241,46) Error: Duplicate identifier "Action". I don’t see something wrong in the code and since this module was giving no problems before it is a mystery to me. I have included the working Delphi version and the erroneous Lazarus version. Many thanks in advance, Chris