Recent

Author Topic: Does ReadComponentRes function work correctly.  (Read 6099 times)

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Does ReadComponentRes function work correctly.
« on: May 22, 2020, 09:21:51 pm »
 Hi

Can anyone check.
Does ReadComponentRes function work correctly?
I always get the error 'External: SIGSEGV' when call it.


dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Does ReadComponentRes function work correctly.
« Reply #1 on: May 23, 2020, 03:44:19 am »
Ok.
Code
Code: Pascal  [Select][+][-]
  1. procedure TLanguageResourceManagerEh.ReadComponentResource(
  2.   Component: TComponent; ResourceName: String);
  3. var
  4.   ConsumerItfs: ILanguageResourceLoadNotificationConsumer;
  5.   {$IFDEF FPC}
  6.   HRs: {%H-}HRSRC;
  7.   {$ELSE}
  8.   HRs: HRSRC;
  9.   {$ENDIF}
  10.   HIn: HINST;
  11. begin
  12.   {$IFDEF FPC}
  13.   HIn := HInstance;
  14.   {$ELSE}
  15.   HIn := FindResourceHInstance(FindClassHInstance(Component.ClassType));
  16.   {$ENDIF}
  17.   HRs := FindResource(HIn, PChar(ResourceName), PChar(RT_RCDATA));
  18.  
  19.   if HRs <> 0 then
  20.   begin
  21.     ReadComponentRes(ResourceName, Component);
  22.     if Supports(Component, ILanguageResourceLoadNotificationConsumer, ConsumerItfs) then
  23.       ConsumerItfs.ResourceLanguageChanged;
  24.   end;
  25. end;
  26.  

and two extra screens

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Does ReadComponentRes function work correctly.
« Reply #2 on: May 23, 2020, 03:44:52 am »
Screen two

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Does ReadComponentRes function work correctly.
« Reply #3 on: May 23, 2020, 04:25:49 pm »
Try this test Project.
It have the same error.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var
  34.   testFrm: TForm1;
  35. begin
  36.   testFrm := TForm1.Create(nil);
  37.   ReadComponentRes('TForm1', testFrm);
  38. end;
  39.  
  40. end.

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Does ReadComponentRes function work correctly.
« Reply #4 on: May 23, 2020, 06:30:06 pm »
Hello

I don't want to create a Form in real situation.

Here I used TForm1 to create I simple example of using ReadComponentRes.

---
In real situation I have dfm file with content, and it is not a Form.

EhLibLangConsts.ENU.dfm
Code: Text  [Select][+][-]
  1. object EhLibLanguageConsts: TEhLibLanguageConsts_ENU
  2.   Language = 'English'
  3.  
  4.   ClearSelectedCells = 'Clear selected cells?'
  5.   InvalidTextFormat = 'Invalid text format'
  6.   InvalidVCLDBIFFormat = 'Invalid VCLDBIF format'
  7.   ErrorDuringInsertValue = 'Error during insert value:'
  8. ...
  9. end
  10.  

EhLibLanguageConsts.PAS
Code: Pascal  [Select][+][-]
  1. { TEhLibLanguageConsts }
  2.  
  3.   TEhLibLanguageConsts = class(TComponent)
  4.   private
  5.     FVisibleColumns: String;
  6.     FPageOfPages: String;
  7.   published
  8.     property Language: String read FLanguage write FLanguage; //-'English'
  9.  
  10.     property ClearSelectedCells: String read FClearSelectedCells write FClearSelectedCells;
  11.     property InvalidTextFormat: String read FInvalidTextFormat write FInvalidTextFormat;
  12.     property InvalidVCLDBIFFormat: String read FInvalidVCLDBIFFormat write FInvalidVCLDBIFFormat;
  13.   end;
  14.  

APP.Pas
Code: Pascal  [Select][+][-]
  1. ...
  2. //Link dfm file (It is not a Form file but dfm file)
  3. {$R C:\RADStudio\lazarus\EhLib\Lib\Res\EhLibLangConsts.ENU.dfm}
  4.  
---
And here I want to read EhLibLangConsts.ENU.dfm resource into Component of TEhLibLanguageConsts type.

So I try to use:
Code: Pascal  [Select][+][-]
  1.   ReadComponentRes('TEhLibLanguageConsts_ENU', Component);
  2.  

It works in Delphi but don't work in Lazarus.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Does ReadComponentRes function work correctly.
« Reply #5 on: May 23, 2020, 10:34:15 pm »
It works in Delphi but don't work in Lazarus.

Seems like no one really tested this before and thus no one noticed that ReadComponentRes is buggy. I'm already working on a bugfix.

As a workaround you can do the following (it's a copy of SysReadComponentRes from rtl\objpas\classes\classes.inc with a slight adjustment when calling FindResource; note: on Windows you'll need to use the Windows unit as well):

Code: Pascal  [Select][+][-]
  1. function MyReadComponentRes(HInstance : THandle; const ResName: String; Instance: TComponent): TComponent;
  2.  
  3. Var
  4.   H : TFPResourceHandle;
  5.  
  6. begin
  7.   { Windows unit also has a FindResource function, use the one from
  8.     system unit here.  }
  9.   H:=system.FindResource(HInstance,PChar(ResName) { ensure the PChar variant of FindResource is used! },RT_RCDATA);
  10.   if (PtrInt(H)=0) then
  11.     Result:=Nil
  12.   else
  13.     With TResourceStream.Create(HInstance,ResName,RT_RCDATA) do
  14.       try
  15.         Result:=ReadComponent(Instance);
  16.       Finally
  17.         Free;
  18.       end;
  19. end;

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Does ReadComponentRes function work correctly.
« Reply #6 on: May 23, 2020, 11:26:18 pm »
Seems like no one really tested this before and thus no one noticed that ReadComponentRes is buggy. I'm already working on a bugfix.

Fixed in r45479.

S_Gur

  • New member
  • *
  • Posts: 8
Re: Does ReadComponentRes function work correctly.
« Reply #7 on: May 24, 2020, 07:06:26 am »
I downloaded two of your fixed files - resh.inc and sysres.inc. I replaced them with those available in my assembly, in the fpc \ 3.0.4 \ source \ rtl \ inc folder. Then he climbed into the list of packages and added one, forcing Lazarus to rebuild the environment according to the "normal assembly" profile. After that I tried to start the project and got the same Access Violation on the same line - ReadComponentRes (ResourceName, Component); Hence the question - did I somehow improperly execute the Lazarus patch or did you still not completely correct the error? I apologize for my English - I don’t have much with it ...

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Does ReadComponentRes function work correctly.
« Reply #8 on: May 24, 2020, 07:33:33 am »
I downloaded two of your fixed files - resh.inc and sysres.inc. I replaced them with those available in my assembly, in the fpc \ 3.0.4 \ source \ rtl \ inc folder. Then he climbed into the list of packages and added one, forcing Lazarus to rebuild the environment according to the "normal assembly" profile. After that I tried to start the project and got the same Access Violation on the same line - ReadComponentRes (ResourceName, Component); Hence the question - did I somehow improperly execute the Lazarus patch or did you still not completely correct the error? I apologize for my English - I don’t have much with it ...

You need to rebuild your FPC installation, rebuilding Lazarus isn't enough.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Does ReadComponentRes function work correctly.
« Reply #9 on: May 24, 2020, 10:23:09 am »
I downloaded two of your fixed files - resh.inc and sysres.inc. I replaced them with those available in my assembly, in the fpc \ 3.0.4 \ source \ rtl \ inc folder. Then he climbed into the list of packages and added one, forcing Lazarus to rebuild the environment according to the "normal assembly" profile. After that I tried to start the project and got the same Access Violation on the same line - ReadComponentRes (ResourceName, Component); Hence the question - did I somehow improperly execute the Lazarus patch or did you still not completely correct the error? I apologize for my English - I don’t have much with it ...

As Cyrax said, rebuilding Lazarus does not rebuild FPC and Lazarus only ships with the RTL and packages sources anyway to allow navigating. Instead you'll have to download the sources of FPC 3.0.4, apply the patch and completely build and install that instead.

S_Gur

  • New member
  • *
  • Posts: 8
Re: Does ReadComponentRes function work correctly.
« Reply #10 on: May 24, 2020, 10:40:44 am »
I'm understood, thank you

S_Gur

  • New member
  • *
  • Posts: 8
Re: Does ReadComponentRes function work correctly.
« Reply #11 on: May 27, 2020, 08:42:25 am »
Seems like no one really tested this before and thus no one noticed that ReadComponentRes is buggy. I'm already working on a bugfix.

Fixed in r45479.

Please tell me, your corrected modules can be used to rebuild the stable version FPC?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Does ReadComponentRes function work correctly.
« Reply #12 on: May 27, 2020, 09:50:42 am »
For this I assume that your Lazarus is installed as C:\Lazarus\2.0.8, adjust this to your paths accordingly.

  • Download the FPC release build environment for 3.0.4 from here (the file is fpcbuild-3.0.4.zip)
  • Extract the build environment (for this example I assume C:\FPC\fpcbuild-3.0.4)
  • Apply the changes from r45479; the source is found in fpcsrc
  • Open a command line window in the directory C:\FPC\fpcbuild-3.0.4
  • Execute make install NOGDB=1 INSTALL_PREFIX=C:\FPC\3.0.4 (for this example I simply assume that you install C:\FPC\3.0.4, but you can pick your own destination, but do not use the directory with the existing FPC in Lazarus just in case something goes wrong)
  • Copy C:\Lazarus\2.0.8\fpc\3.0.4\bin\<CPU>-<OS>\fpc.cfg to C:\FPC\3.0.4\bin\<CPU>-<OS>\fpc.cfg and inside that file search and replace all paths from C:\Lazarus\2.0.8\fpc\3.0.4 to C:\FPC\3.0.4
  • Point Lazarus to the new FPC binary in C:\FPC\3.0.4\bin\<CPU>-<OS>\fpc.exe and change the sources directory as well
  • You should now be able to use your recompiled FPC 3.0.4 release

S_Gur

  • New member
  • *
  • Posts: 8
Re: Does ReadComponentRes function work correctly.
« Reply #13 on: May 27, 2020, 11:46:30 am »
Thank you very much for the detailed instructions. Everything worked out

dmitryb

  • Jr. Member
  • **
  • Posts: 62
Re: Does ReadComponentRes function work correctly.
« Reply #14 on: May 27, 2021, 07:06:13 pm »
I tested in Lazarus 2.0.12
Looks like problem in ReadComponentRes still present.

Can anyone confirm that the fix (r45479) is present for this version?


 

TinyPortal © 2005-2018